LeetCode #231: Power of Two
• 37 words • 1 min • updated
python
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
if n <= 0:
return False
while n & 1 == 0:
n >>= 1 # n //= 2
return n == 1∎
Connections
Shared tags