2023-11-29 12:45:36 +01:00
|
|
|
public class Solution {
|
2024-03-02 21:01:53 +01:00
|
|
|
public int hammingWeight(int n) {
|
|
|
|
int bits = 0;
|
2023-11-29 12:45:36 +01:00
|
|
|
|
2024-03-02 21:01:53 +01:00
|
|
|
for (int i = 0; i < 32; ++i) {
|
|
|
|
if ((n & (1 << i)) != 0) {
|
|
|
|
++bits;
|
|
|
|
}
|
2023-11-29 12:45:36 +01:00
|
|
|
}
|
2024-03-02 21:01:53 +01:00
|
|
|
|
|
|
|
return bits;
|
|
|
|
}
|
2023-11-29 12:45:36 +01:00
|
|
|
}
|