class Solution:
def isPowerOfFour(self, n: int) -> bool:
if n == 1:
return True
if n <= 0 or n % 4:
return False
return self.isPowerOfFour(n // 4)class Solution:
def isPowerOfFour(self, n: int) -> bool:
if n < 0:
return False
while n > 1:
if n % 4:
return False
n //= 4
return n == 1class Solution:
def isPowerOfFour(self, n: int) -> bool:
return n > 0 and log(n, 4) % 1 == 0class Solution:
def isPowerOfFour(self, n: int) -> bool:
if n < 0:
return False
for i in range(0, 32, 2):
if n == (1 << i):
return True
return Falseclass Solution:
def isPowerOfFour(self, n: int) -> bool:
return n > 0 and (n & (n - 1)) == 0 and (n & 0x55555555) == nclass Solution:
def isPowerOfFour(self, n: int) -> bool:
return n > 0 and (n & (n - 1)) == 0 and (n % 3 == 1)