Python super simple solutions, and fast!


  • 1
    Z
    class Solution(object):
        """
        600 / 600 test cases passed.
        Status: Accepted
        Runtime: 44 ms
        Submitted: 0 minutes ago
        """
        def hammingWeight(self, n):
            """
            :type n: int
            :rtype: int
            """
            binary_str_n = bin(n)
            hamming_weight = binary_str_n.count('1')
            return hamming_weight

  • 0
    Q

    Hi,
    just out of curiosity, what if this is an interview question, are we supposed to apply build-in function or design a basic algorithm with minimum assumption?


Log in to reply
 

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