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);
}
相關文章
- leetCode(Using C)——461. Hamming DistanceLeetCode
- 【LeetCode】461.Hamming Distance_EASY(一)LeetCode
- 漢明距離(Hamming distance)
- HDU 4712Hamming Distance(隨機函式運用)隨機函式
- LeetCode 461. 漢明距離LeetCode
- [Leetcode] Edit DistanceLeetCode
- Leetcode Edit DistanceLeetCode
- Leetcode-Edit DistanceLeetCode
- Edit Distance leetcode javaLeetCodeJava
- Leetcode-One Edit DistanceLeetCode
- LeetCode-Shortest Word DistanceLeetCode
- [LeetCode] 243. Shortest Word DistanceLeetCode
- LeetCode-Shortest Word Distance IILeetCode
- LeetCode-Shortest Word Distance IIILeetCode
- [LeetCode] 2739. Total Distance TraveledLeetCode
- LeetCode之Shortest Distance to a Character(Kotlin)LeetCodeKotlin
- [LeetCode] 244. Shortest Word Distance IILeetCode
- LeetCode-Rearrange String k Distance ApartLeetCode
- LeetCode-Shortest Distance from All BuildingsLeetCodeUI
- Java解決LeetCode72題 Edit DistanceJavaLeetCode
- [LeetCode] 1385. Find the Distance Value Between Two ArraysLeetCode
- simhash&hamming distince
- [LeetCode] 317. Shortest Distance from All BuildingsLeetCodeUI
- 【leetcode】72. Edit Distance 編輯距離計算LeetCode
- Matrix Distance
- LeetCode 1334. Find the City With the Smallest Number of Neighbors at a Threshold Distance??LeetCode
- 461.漢明距離(c++實現)C++
- 海明碼(Hamming Code)的知識點
- [Over-Distance] Ubuntu 24.04 LTS UpdateUbuntu
- 錯誤 1 error LNK2019: 無法解析的外部符號 "public: __thiscall Distance::Distance(int)" (??0Distance@@QAE@H@Z),該符...Error符號
- ABC359 G - Sum of Tree Distance
- POI2012ODL-Distance
- CC Prime Distance On Tree (樹的點分治 + FFT)FFT
- [ABC353F] Tile Distance 題解
- abc359_G Sum of Tree Distance 題解
- 【Lintcode】1623. Minimal Distance In The Array
- Codeforces Round 903 (Div. 3) F. Minimum Maximum Distance
- 相容oracle的edit_distance_similarity 比較兩個字串相似度OracleMILA字串