problem
solution
如果i不是2的指數,那 i&(i-1)
可以找到比i小的2的指數
option 1
1 | class Solution { |
option 2
1 | class Solution { |
option 3
1 | class Solution { |
analysis
- option 1
- time complexity
O(nlogn)
- space complexity
O(1)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(1)
- time complexity