Python Solution using bit manipulation using concept of MAX_INT (idea from previous problems on power)

  • 0
        def isPowerOfFour(self, num):
            :type num: int
            :rtype: bool
            if num<1:
                return False
            if num==1:
                return True
            if  num%2!=0:
                return False
            return (num&num-1)==0 and num&1431655765!=0#(2^30+2^28+2^26....2^0=1431655765)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.