public class Solution {
public boolean isPowerOfFour(int n) {
if(n<1) return false;
int root = (int)Math.sqrt(n);
return (n&(n1))==0 && nroot*root==0;
}
}
Java simple code (without using loops)

The key is to observe that (n & (n1) == 0) is true for all n that are factor of 2. I think the following variant is a bit more intuitive because it basically checks that the sqrt of the given number n is a factor of 2 and that that sqrt*sqrt = the given number
public boolean isPowerOfFour(int n) { if(n<1) return false; int root = (int)Math.sqrt(n); return (root&(root1))==0 && root*root==n; } }