Problem Solving/LeetCode
Today's Challenge
fabichoi
2022. 5. 26. 23:45
https://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
오랫만에 매우 단순한 문제.
그냥 2진수로 바꾼다음에 1이 몇개인지 세면 된다.
class Solution:
def hammingWeight(self, n: int) -> int:
return str(bin(n))[2:].count('1')
반응형