class Solution:
def isPowerOfFour(self, num: int) -> bool:
# time O(N/4)
if num <= 0 :
return False
power = 0
x = 0
while x < num :
x = 4**power
if x == num:
return True
power += 1
return False
solution follow up:
class Solution:
# main idea: num is power of 2 and binary form '1' at odd position; big condition: num >0
def isPowerOfFour(self, num: int) -> bool:
return num > 0 and num & (num-1)==0 and ((num & 0x55555555) == num)