problems(java): add “191. Number of 1 Bits”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-11-29 12:45:36 +01:00
parent 62436de0d0
commit 8f34be49bb
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,13 @@
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;
}
}