A C++ solution, no loop


  • 0
    P
    class Solution {
    public:
        bool isPowerOfFour(int num) {
            if(num == 0)
                return false;
            
            if( !(num & (num-1)) &&  (num & 0x55555555) )
                return true;
            else
                return false;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.