Without Recursion/Loop Using Log


  • 0
    A
    public static boolean isPowerOfFour(int num){
    	if(num <= 0) return false;
    		
         double val = Math.log(num)/Math.log(4);
         return (num == 1 || Math.floor(val) == val);
        }

Log in to reply
 

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