number of 1 bits
题目地址:https://leetcode.com/problems/number-of-1-bits/
解答:
public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int count = 0; while(n!=0){ count++; n&=(n-1); } return count; } }
题目地址:https://leetcode.com/problems/number-of-1-bits/
解答:
public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int count = 0; while(n!=0){ count++; n&=(n-1); } return count; } }