https://leetcode.com/problems/number-of-1-bits/description/
Number of 1 Bits - LeetCode
Number of 1 Bits - Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight [http://en.wikipedia.org/wiki/Hamming_weight]). Note: * Note that in some languages, such as Java, there is no un
leetcode.com
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 |
댓글