일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- npm
- var
- AI
- dotenv
- JavaScript
- Clone
- security
- 앙상블
- vuetify
- VUE
- BOJ
- C#
- nginx
- TypeScript
- webpack
- leetcode
- vue.js
- bash
- type
- C++
- property
- scss
- git
- generic
- machine learning
- docker
- 보안
- loop
- condition
- Python
Archives
- Today
- Total
ice rabbit programming
[LeetCode] 191. Numbers of 1 Bits 본문
728x90
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
정수형으로 들어온 숫자에 대해, 이진수로 변환했을 때 1인 비트의 개수를 구하는 문제이다. 파이썬으로 풀었더니, 내장 함수에 의해서 쉽게 구현할 수 있었다.
class Solution:
def hammingWeight(self, n: int) -> int:
return str(bin(n)).count('1')
728x90
'PS > LeetCode' 카테고리의 다른 글
[LeetCode] 231. Power of Two (0) | 2020.12.08 |
---|---|
[LeetCode] 217. Contains Duplocate (0) | 2020.12.08 |
[LeetCode] 190. Reverse Bits (0) | 2020.12.08 |
[LeetCode] 389. Find the Difference (0) | 2020.12.08 |
[LeetCode] 448. Find All Numbers Disappeared in an Array (0) | 2020.09.26 |