def isPowerOfFour(self, num):
return num!=0 and num&(num-1) == 0 and num|5726623061 == 5726623061
Nice code! Can you explain how do you create the magic number?
The number is 4^0+4^1+4^2...+4^n = 2^0+2^2+2^4...+2^2n. Since the integer is 32 bits, 2n need to be smaller than 31. Then just calculate this magic number ^_^.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.