Offer15.二进制中1的个数/Solution.java
public class Solution {
    // you need to treat n as an unsigned value

    // 诸位判断，与运算 &
    public int hammingWeight(int n) {
        int res = 0;
        while (n != 0) {
            res += n & 1;
            n >>>= 1;
        }
        return res;
    }

    //
    public int hammingWeight2(int n) {
        int res = 0;
        while (n != 0) {
            res++;
            n &= (n - 1);
        }
        return res;
    }
}