Cpp: use bitset & count


  • 0
    A
    class Solution {
    public:
        int hammingWeight(uint32_t n) {
        bitset<32> k(n);
        return (k.count());        
           
        }
    };

Log in to reply
 

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