191. Number of 1 Bits
Number of 1 Bits
Solution
public class Solution {
public int hammingWeight(int n) {
int result = 0;
for (int i = 0; i <= 31; i++) {
if ((n >>> i & 0x1) == 1) result ++;
}
return result;
}
}Last updated