342. Power of Four
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 : 49.15 %
class Solution:
def isPowerOfFour(self, n: int) -> bool:
return n == 1 or \
n > 0 and (bin(n)[2:][-2:].count('1') == 0) \
and (bin(n)[-3:1:-2].count('1') == 1) \
and (bin(n)[-4:1:-2].count('1') == 0)
class Solution:
def isPowerOfFour(self, n: int) -> bool:
return n >= 1 and (n == 1 or n // 4 * 4 == n and self.isPowerOfFour(n // 4))