天天看點

LeetCode 461 Hamming Distance(漢明距離)

Q: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.

注:兩個等長字元串之間的漢明距離(英語:Hamming distance)是兩個字元串對應位置的不同字元的個數。換句話說,它就是将一個字元串變換成另外一個字元串所需要替換的字元個數。

Note:

0 ≤ x, y < 231.

Example:

Explanation:

1 (0 0 0 1)

4 (0 1 0 0)

The above arrows point to positions where the corresponding bits are different

S:

public class Solution {

}

bitCount 自實作方案:

繼續閱讀