1-line C++ Recursive Solution


  • 1
    class Solution {
    public:
        int hammingWeight(uint32_t n) {
            return (n%2?1:0)+(n==0?0:hammingWeight(n/2));
        }
    };

Log in to reply
 

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