C++ one key line


  • 0
    A
    class Solution {
    public:
        int hammingWeight(uint32_t n) {
            int ans = 0;
            for (int i=0; i<32; ++i){
                ans += n>>i & 1;  // key line
            }
            return ans;
        }
    };

Log in to reply
 

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