Java 2 lines && easy to understand


  • 0
    L

    The idea is the same with as follows :
    231. Power of Two
    326. Power of Three
    the only difference is that this problem has to add a condition:x*x == num

    public class Solution {
        public boolean isPowerOfFour(int num) {
            int x = (int)Math.sqrt(num);
            //1073741824 is 4^15,  4^16 is bigger than int 
            return(num > 0 && 1073741824 % num == 0 && x*x == num);
        }
    }
    

Log in to reply
 

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