My AC java solution


  • 0
    I
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int count = 0;
            int i = 0;
            do{
                if((n & 1) == 1) count++;
                n >>>= 1;
                i++;
            }while(i <= 32);
            return count;
        }
       
    }

Log in to reply
 

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