so it's making it hard to search. If I want to take a number and determine whether it's in the 1's, 10's, 100's, etc. how would I do that? For instance:
4 -> 1
6 -> 1
17 -> 10
32 -> 10
99 -> 10
100 -> 100
872 -> 100
999 -> 100
I'm hoping there's a way to do this mathematically without using a loop or hash map.
Finding the exponent?
Just divide by 10 until 0 and increment a counter
Right, I know of that way, but I'm hoping there's a way to do it and avoid using a loop
Ahh, there might be
Go for readability over speed.
This is for leetcode, so I don't really care about readability
log with base 10
well this can be solved using log with base 10 10 ^ (int(log x))
Jesus how many ways are you going to say the same thing
Обсуждают сегодня