Power of Four

Problem: Power of Four

Binary number of power of four always starts with a one and pairs of zero.

Code in Python:

class Solution(object):
    def isPowerOfFour(self, num):
        """
        :type num: int
        :rtype: bool
        """
        if num == 0: return False
        while num & 3 == 0:
            num >>= 2
        return num == 1

results matching ""

    No results matching ""