Leetcode 461. Hamming Distance
2017-03-18 04:54
344 查看
public class Solution { private final int LENGTH = 32; public int hammingDistance(int x, int y) { int[] bits_x = new int[LENGTH]; int[] bits_y = new int[LENGTH]; // calculate binary codes for x and y int k = 0; while (x > 0) { bits_x[k++] = x%2; x /= 2; } k = 0; while (y > 0) { bits_y[k++] = y%2; y /= 2; } // count the distance int distance = 0; for (int i=0; i<LENGTH; i++) { if (bits_x[i] != bits_y[i]) distance++; } return distance; } }
相关文章推荐
- [leetcode]461. Hamming Distance --python
- leetcode----461. Hamming Distance
- Leetcode #461. Hamming Distance
- [LeetCode]461. Hamming Distance
- [LeetCode] 461. Hamming Distance 汉明距离
- LeetCode - 461. Hamming Distance
- LeetCode 461. Hamming Distance-python
- [Leetcode从零开刷]461. Hamming Distance
- leetcode 461. Hamming Distance(C语言)
- leetcode 461. Hamming Distance 解题报告
- LeetCode 461. Hamming Distance
- [LeetCode]461. Hamming Distance
- [leetcode]461. Hamming Distance
- leetcode - 461. Hamming Distance (bit mannipulation)
- 【leetCode】461. Hamming Distance
- LeetCode--461. Hamming Distance(汉明距离)Python
- LeetCode 461. Hamming Distance
- LeetCode 461. Hamming Distance (汉明距离)
- leetcode 461. Hamming Distance
- 【LeetCode】461. Hamming Distance【E】【90】