PS/LeetCode
[LeetCode] 191. Numbers of 1 Bits
판교토끼
2020. 12. 8. 23:34
728x90
leetcode.com/problems/number-of-1-bits/
Number of 1 Bits - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
정수형으로 들어온 숫자에 대해, 이진수로 변환했을 때 1인 비트의 개수를 구하는 문제이다. 파이썬으로 풀었더니, 내장 함수에 의해서 쉽게 구현할 수 있었다.
class Solution:
def hammingWeight(self, n: int) -> int:
return str(bin(n)).count('1')
728x90