Skip to content

Files

Latest commit

Zanger67/leetcodeZanger67/leetcode
Zanger67/leetcode
and
Zanger67/leetcode
Mar 16, 2025
03398f8 · Mar 16, 2025

History

History
42 lines (31 loc) · 1.16 KB

_342. Power of Four.md

File metadata and controls

42 lines (31 loc) · 1.16 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : March 04, 2025

Last updated : March 04, 2025


Related Topics : Math, Bit Manipulation, Recursion

Acceptance Rate : 49.15 %


Solutions

Python

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))