One line python without bin()

  • 0

    I don't think the interviewer will allow bin() function for this problem...

    class Solution(object):
        def hammingWeight(self, n):
            :type n: int
            :rtype: int
            return (n & 1) + self.hammingWeight(n >> 1) if n != 0 else 0

Log in to reply

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