leetcode -. 191 digits 1

class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        return bin(n).count('1')
When execution: 16 ms, beat the 94.92% of all users in Python submission
Memory consumption: 11.7 MB, defeated 31.64% of users in all Python submission
 
                                                                                                  ——2019.10.10

Guess you like

Origin www.cnblogs.com/taoyuxin/p/11649290.html