Leetcode: Power of Four

Given an integer (signed 32 bits), write a function to check whether it is a power of 4.



Similar Problems:


Given an integer (signed 32 bits), write a function to check whether it is a power of 4.

Example:
Given num = 16, return true. Given num = 5, return false.

Follow up: Could you solve it without loops/recursion?

Github: code.dennyzhang.com

Credits To: leetcode.com

Leave me comments, if you have better ways to solve.


## Blog link: https://code.dennyzhang.com/power-of-four
class Solution(object):
    def isPowerOfFour(self, num):
        return ((num - 1) & num == 0 and (num-1) % 3 == 0)
linkedin
github
slack

Share It, If You Like It.

Leave a Reply

Your email address will not be published.