1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/problems/java/number-of-1-bits.java
Matej Focko 8f34be49bb
problems(java): add “191. Number of 1 Bits”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-11-29 12:45:36 +01:00

13 lines
241 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;
}
}