4ms C++ One Line recursion solution


  • 0
    P
    class Solution {
    public:
        int hammingWeight(uint32_t n) {
            return n == 0 ? 0 : (n & 1) + hammingWeight(n >> 1);
        }
    };

Log in to reply
 

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