342 - Power Of Four
Written on November 6, 2017
Tweet
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.
class Solution(object):
def isPowerOfFour(self, num):
"""
:type num: int
:rtype: bool
"""
return num != 0 and num & (num - 1) == 0 and num & 1431655765 == num