342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
Example 1:
Input: 16 Output: true Example 2:
Input: 5 Output: false Follow up: Could you solve it without loops/recursion?
思路:跟上题一样,4**18%num求余,为0 再加一条,num%3求余不为2
代码:python3
class Solution:
def isPowerOfFour(self, num: int) -> bool:
return num>0 and 4**18%num==0 and num%3!=2
复制代码