LeetCode191-位1的个数 LeetCode191-位1的个数转字符串计算长度123public int hammingWeight1(int n) { return Integer.toBinaryString(n).replace("0","").length(); } 位运算符123456789//位运算 public static int hammingWeight2(int n) { int count = 0; while (n != 0) { count += n & 1; n >>>= 1; } return count; } LeetCode 力扣 计算机基础 本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处! LeetCode203-移除链表元素 Previous LeetCode141-环形链表 Next Please enable JavaScript to view the comments