Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- 자연어처리
- SW Expert Academy
- 금융문자분석경진대회
- ChatGPT
- 더현대서울 맛집
- 코로나19
- 우분투
- programmers
- Kaggle
- AI 경진대회
- Git
- gs25
- Baekjoon
- 파이썬
- dacon
- 편스토랑 우승상품
- 캐치카페
- 데이콘
- github
- Docker
- 편스토랑
- 백준
- hackerrank
- ubuntu
- 프로그래머스 파이썬
- PYTHON
- 맥북
- 프로그래머스
- leetcode
- Real or Not? NLP with Disaster Tweets
Archives
- Today
- Total
솜씨좋은장씨
[leetCode] 461. Hamming Distance (Python) 본문
728x90
반응형
The Hamming distance between two integers is the number of positions at which the corresponding bits are different.
Given two integers x and y, calculate the Hamming distance.
Note:
0 ≤ x, y < 231.
Example:
Input: x = 1, y = 4
Output: 2
Explanation:
1 (0 0 0 1)
4 (0 1 0 0)
↑ ↑
The above arrows point to positions where the corresponding bits are different.
Soltuion
class Solution:
def hammingDistance(self, x: int, y: int) -> int:
return bin(x^y).count('1')
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[leetCode] 237. Delete Node in a Linked List (Python) (0) | 2021.01.14 |
---|---|
[leetCode] 492. Construct the Rectangle (Python) (0) | 2021.01.13 |
[leetCode] 791. Custom Sort String (Python) (0) | 2021.01.11 |
[leetCode] 821. Shortest Distance to a Character (Python) (0) | 2021.01.08 |
[leetCode] 1619. Mean of Array After Removing Some Elements (Python) (0) | 2021.01.01 |
Comments