코-딩/Leetcode
[leetcode] 338. Counting Bits
힞뚜루마뚜루
2022. 10. 23. 15:48
728x90
문제 : https://leetcode.com/problems/counting-bits/
난이도 : Easy
풀이
class Solution:
def countBits(self, n: int) -> List[int]:
arr = []
for i in range(n + 1):
arr.append(bin(i).count('1'))
return arr
파이썬에는 함수가 많다. 최고야
1) bin()
2) count()
728x90