mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-09 15:59:06 +01:00
13 lines
201 B
Java
13 lines
201 B
Java
public class Solution {
|
|
public int hammingWeight(int n) {
|
|
int bits = 0;
|
|
|
|
for (int i = 0; i < 32; ++i) {
|
|
if ((n & (1 << i)) != 0) {
|
|
++bits;
|
|
}
|
|
}
|
|
|
|
return bits;
|
|
}
|
|
}
|