Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 342 Bytes

bit-manipulation.md

File metadata and controls

22 lines (17 loc) · 342 Bytes

Bit Manipulation

17. Number of One bits

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int ans = 0;

        while(n) {
            n = n & (n - 1);
            ans++;
        }

        return ans;
    }
};