def isPowerOfTwo(self, n: int) -> bool:
# power of two will always be positive
# Method 1: keep dividing 2
# time O(logn)
# space O(1)
if not n: return False
while n % 2 == 0:
n //= 2
return n == 1
# Method 2: only have one 1 in binary
# time O(1)
# space O(1)
return n > 0 and (n & -n) == n
# Method 3:
# time O(1)
# space O(1)
return n > 0 and (1<<30)%n==0