Easy Java Bit Shift Solution


  • 3
    J
    public class Solution {
        public boolean isPowerOfTwo(int n) {
            if(n < 1) return false;
            if(n == 1) return true;
            while((n & 1) != 1){
                n >>= 1;
            }
            if(n > 1) return false;
            else return true;
        }
    }

Log in to reply
 

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