C++ 1 line, 4 ms solution with bitset


  • 1
    T

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


Log in to reply
 

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