https://leetcode.com/problems/number-of-1-bits/description/
1
2
3
|
class Solution:
def hammingWeight(self, n: int) -> int:
return str(bin(n)).count('1')
|
cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 1446. Consecutive Characters (0) | 2023.01.14 |
---|---|
leetcode 2042. Check if Numbers Are Ascending in a Sentence (0) | 2023.01.13 |
leetcode 2138. Divide a String Into Groups of Size k (0) | 2023.01.12 |
leetcode 2180. Count Integers With Even Digit Sum (0) | 2023.01.12 |
leetcode2351. First Letter to Appear Twice (0) | 2023.01.11 |
댓글