Java solution with >>> operator


  • 2
    S
        public int hammingWeight(int n) {
        int count =0;
        for(int i =0; i< 32; i++){
            if((n & 1) == 1){
                count++;
            }
            n >>>= 1;
        }
        return count;
        
    }

Log in to reply
 

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