LeetCode: Hamming Distance

 1 public class Solution {
 2     public int hammingDistance(int x, int y) {
 3         int ans = 0;
 4         while (x > 0 || y > 0) {
 5             ans += (x % 2) ^ (y % 2);
 6             x /= 2;
 7             y /= 2;
 8         }
 9         return ans;
10     }
11 }
原文地址:https://www.cnblogs.com/yingzhongwen/p/6433819.html