def isPowerOfTwo(self, n):
:type n: int
return n&-n == n and n != 0
sorry,I don't understand.Can you explain it to me?
sorry,I don't understand n&-n == n.Can you explain it to me?
1 --> 1
2 --> 10
4 --> 100
8 --> 1000
all number which are 2's power must be only one 1 plus some 0, if you write to binary
n&-n get right most 1. if it is == to n means the number is 1 plus some 0
tried the code and works fine!
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.