C++ code without recursion or iteration


  • 0
    A
    class Solution {
    public:
        bool isPowerOfFour(int num) {
            if(num <= 0)
            {
                return false;
            }
            
            int bitPattern = 0x55555555;
            int maxPower2 = 0x1<<30;
    
            return maxPower2 % num ? false:((bitPattern & num)==num ? true: false);
        }
    };

Log in to reply
 

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