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
- Real or Not? NLP with Disaster Tweets
- leetcode
- 맥북
- 파이썬
- Kaggle
- Git
- SW Expert Academy
- 금융문자분석경진대회
- Baekjoon
- AI 경진대회
- github
- 편스토랑
- 프로그래머스
- programmers
- Docker
- PYTHON
- 우분투
- gs25
- 캐치카페
- 데이콘
- 편스토랑 우승상품
- hackerrank
- 자연어처리
- 프로그래머스 파이썬
- 백준
- ubuntu
- dacon
- ChatGPT
- 더현대서울 맛집
- 코로나19
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