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 }