There is the Loop Solution for Java


  • 3

    I saw all the solutions are the one-line no loop solution. So I post a loop solution.

    public boolean isPowerOfFour(int num) {
            if(num == 0)
                return false;
            while(num%4  == 0){
                num = num /4;
            }
            if(num != 1)
                return false;
            return true;
        }
    

Log in to reply
 

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