leetcode 191
-
191. Number of 1 BitsProgramming/leetcode 2021. 2. 1. 17:19
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