Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

I don't know why it is still very slow compare to other solution. Any other good method??? so confuseddd

if(n<=0) return false; while(n%2==0){ n/=2; } return n==1;

Your method runs in O(lgn) time, where n is the number of bits used to represent the number. Try using bit-wise operation then you can reduce the time complexity down to O(1), which is faster.

Yep, you are right, thanks a lot. Dude

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.