Simple C++ Solution based on the Power-of-Two


  • 0
    S
    class Solution {
    public:
        bool isPowerOfFour(int num) {
            int count = 0;  
            int loop = 0;
            while (num > 0)  
            {  
                count+=(num&0x01);
                loop++;
                num>>=1;  
            }  
            return count==1 && loop%2==1;
        }
    };

Log in to reply
 

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