1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02:00
LeetCode/java/number-of-1-bits.java

14 lines
241 B
Java
Raw Normal View History

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;
}
}