Solution 1 - Bit Mask
Power of four means: positive, exactly one set bit, and that bit is in an even position.
""" 0342.1 - Power of Four - Solution 1 - Bit Mask """
class Solution:
def isPowerOfFour(self, n: int) -> bool:
return n > 0 and (n & (n - 1)) == 0 and (n & 0x55555555) != 0
if __name__ == "__main__":
assert Solution().isPowerOfFour(16)