191. Number of 1 Bits leetcode solution in c++

C++ Solution for Number of 1 Bits in Leetcode

class Solution {
public:
    int hammingWeight(uint32_t n) {
        int count = 0;
        while (n != 0) {
            count++;
            n = n & (n - 1);
        }
        return count;
    }
};