The easiest way (use switch case)


  • 0
    L
    public boolean isPowerOfFour(int num) {
    	if(num <= 0) return false;
    	switch(num){
        	    case 1 : case 4 : case 16 : case 64 : case  256:
        	    case 1024 : case 4096 : case 16384 : case 65536 :
        	    case 262144 : case 1048576 : case 4194304 : 
        	    case 16777216 : case 67108864 : case 268435456 :
        	    case 1073741824 : 
        		return true;
        	    default : return false;
    	}
    }

Log in to reply
 

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