We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difficulty: 简单
Related Topics: 位运算
两个整数之间的 指的是这两个数字对应二进制位不同的位置的数目。
给你两个整数 x 和 y,计算并返回它们之间的汉明距离。
x
y
示例 1:
输入:x = 1, y = 4 输出:2 解释: 1 (0 0 0 1) 4 (0 1 0 0) ↑ ↑ 上面的箭头指出了对应二进制位不同的位置。
示例 2:
输入:x = 3, y = 1 输出:1
提示:
Language: JavaScript
/** * @param {number} x * @param {number} y * @return {number} */ var hammingDistance = function(x, y) { return (x^y).toString(2).split('').filter(i => i === '1').length };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
461. 汉明距离
Description
Difficulty: 简单
Related Topics: 位运算
两个整数之间的 指的是这两个数字对应二进制位不同的位置的数目。
给你两个整数
x
和y
,计算并返回它们之间的汉明距离。示例 1:
示例 2:
提示:
Solution
Language: JavaScript
The text was updated successfully, but these errors were encountered: