Leetcode 342 Solution

This article provides solution to leetcode question 342 (power-of-four)

https://leetcode.com/problems/power-of-four

Solution

class Solution {
public:
    bool isPowerOfFour(int num) {
        if (num <= 0)
            return false;

        if (num & 0xAAAAAAAA)
            return false;

        return (num & (num - 1)) == 0;
    }
};