题目链接题目描述实现代码 题目链接位1的个数 题目描述 实现代码思路:运用了位运算的思想,循环 n &= n-1,直至n为0; 实现代码如下: public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int result = 0; while(n != 0) { n &= n-1; result++; } return result; }}