Java solution with no built-ins


  • 0
    L
    public class Solution {
        public boolean isPowerOfFour(int num) {
            if(num<1 || (num&(num-1))!=0) {
                return false;
            }
            int count=0;
            while(num!=0) {
                count++;
                num = num>>>1;
            }
            return count%2!=0;        
        }
    }
    

Log in to reply
 

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