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



SOMJANG/CODINGTEST_PRACTICE
1일 1문제 since 2020.02.07. Contribute to SOMJANG/CODINGTEST_PRACTICE development by creating an account on GitHub.
github.com
'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 |