231. Power of Two
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : March 04, 2025
Last updated : March 04, 2025
Related Topics : Math, Bit Manipulation, Recursion
Acceptance Rate : 48.22 %
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
return n > 0 and bin(n).count('1') == 1
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
return n >= 1 and (n == 1 or n // 2 * 2 == n and self.isPowerOfTwo(n // 2))