191. Number of 1 Bits

191. Number of 1 Bits

题目:

https://leetcode.com/problems/number-of-1-bits/

难度:

Easy

转成二进制,数1的个数

class Solution(object):
    def hammingWeight(self, n):
        """
        :type n: int
        :rtype: int
        """
        count = 0
        while n > 0:
            count += n % 2
            n = n//2
        return count
    原文作者:oo上海
    原文地址: https://www.jianshu.com/p/797161f41ac8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞