Home Number of 1 Bits
Post
Cancel

Number of 1 Bits

Leetcode Problem

Number of 1 Bits

32bit의 양수형 정수가 주어졌을 때, 1의 개수를 구하는 문제입니다.

1
2
3
class Solution:
    def hammingWeight(self, n: int) -> int:
        return bin(n).count('1')

내부함수를 이용하여 간단하게 구해줬습니다.





참고

This post is licensed under CC BY 4.0 by the author.