-
191. Number of 1 BitsProgramming/leetcode 2021. 2. 1. 17:19728x90
2월 1일 문제
십진수를 이진수로 변환했을때 1비트가 몇개 있느냐 검색하는 문제
난이도는 쉽다.
def hammingWeight(self, n: int) -> int: count = 0 while n >0: if n & 1 == 1: count += 1 n>>=1 return count
def hammingWeight(self, n: int) -> int: count = 0 print(n) while n >0: count += n%2 n//= 2 return count
'Programming > leetcode' 카테고리의 다른 글
121. Best Time to Buy and Sell Stock (0) 2021.02.02 561. Array Partition I (0) 2021.02.02 15. 3Sum (0) 2021.02.01 42. Trapping Rain Water (0) 2021.02.01 1. Two Sum (0) 2021.01.28