Leetcode 191 Solution
This article provides solution to leetcode question 191 (number-of-1-bits)
Access this page by simply typing in "lcs 191" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/number-of-1-bits
Solution
class Solution {
public:
int hammingWeight(uint32_t n) {
int cnt = 0;
while (n)
{
n = n & (n - 1);
cnt++;
}
return cnt;
}
};