Posted on

Description

Submission

class Solution {
public:
    bool isPowerOfFour(int n) {
        if(n == 0) return false;
        if(n == 1) return true;
        if(n % 4) return false;
        return isPowerOfFour(n / 4);
    }
};
class Solution {
public:
    bool isPowerOfFour(int n) {
        return (n > 0) && !((n-1)&n) && !(n&0xaaaaaaaa);
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *