LeetCode 461. Hamming Distance
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.
計算兩個二進數相同位置上不同的數量
異或之後看1的個數就好了,1行程式碼
public int hammingDistance(int x, int y) {
return Integer.bitCount(x ^ y);
}
相關文章
- 477-Total Hamming Distance
- 漢明距離(Hamming distance)
- [Leetcode] Edit DistanceLeetCode
- LeetCode 461. 漢明距離LeetCode
- [LeetCode] 243. Shortest Word DistanceLeetCode
- [LeetCode] 2739. Total Distance TraveledLeetCode
- LeetCode之Shortest Distance to a Character(Kotlin)LeetCodeKotlin
- [LeetCode] 244. Shortest Word Distance IILeetCode
- [LeetCode] 317. Shortest Distance from All BuildingsLeetCodeUI
- Java解決LeetCode72題 Edit DistanceJavaLeetCode
- [LeetCode] 1385. Find the Distance Value Between Two ArraysLeetCode
- LeetCode 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance??LeetCode
- Kata:Hamming number
- 【leetcode】72. Edit Distance 編輯距離計算LeetCode
- simhash&hamming distince
- 461. 漢明距離
- Matrix Distance
- A - Distance in Tree
- 7.47 CLUSTER_DISTANCE
- 海明碼(Hamming Code)的知識點
- 461.漢明距離(c++實現)C++
- distance(Floyd求最短路)
- POI2012ODL-Distance
- 錯誤 1 error LNK2019: 無法解析的外部符號 "public: __thiscall Distance::Distance(int)" (??0Distance@@QAE@H@Z),該符...Error符號
- 【Lintcode】1623. Minimal Distance In The Array
- [Over-Distance] Ubuntu 24.04 LTS UpdateUbuntu
- 1046 Shortest Distance(簡單模擬)
- ABC359 G - Sum of Tree Distance
- [ABC353F] Tile Distance 題解
- abc359_G Sum of Tree Distance 題解
- Codeforces Round 903 (Div. 3) F. Minimum Maximum Distance
- 題解:AT_abc382_d [ABC382D] Keep Distance
- GAN量化評估方法——IS(Inception Score)和FID(Frechet Inception Distance score)
- 相容oracle的edit_distance_similarity 比較兩個字串相似度OracleMILA字串
- 資料對齊-編輯距離演算法詳解(Levenshtein distance)演算法
- 【LeetCode】如何學習LeetCode?LeetCode
- leetcodeLeetCode
- P9058 [Ynoi2004] rpmtdq 與 P9678 [ICPC2022 Jinan R] Tree DistanceNaN