bit operation


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

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.