1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-10 00:09:06 +01:00
LeetCode/java/number-of-1-bits.java
Matej Focko f0cdb67ac1
chore(java): format
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-03-02 21:01:53 +01:00

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