C++ Recursive solution


  • 0
    G
    class Solution {
    public:
        bool isPowerOfFour(int num) 
        {   
            if((num == 0) || (num == INT_MAX) || (num < 0))
            {
                return (false);
            }
            
            if(num == 1)
            {
                return (true);
            }
            
            return (((num - 1) == 3) || ((num & 3) == 0 && isPowerOfFour(num >> 2)));
        }
    };

Log in to reply
 

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