Power of Four

除了找最末尾1的操作,还需要对num - 1进行模3操作从而去掉可以被2整除的偶数

class Solution(object):
    def isPowerOfFour(self, num):
        """
        :type num: int
        :rtype: bool
        """
        return (num > 0) and (num & (num - 1) == 0) and ((num - 1) % 3 == 0)

results matching ""

    No results matching ""