leetcode 461. Hamming Distance

Orignal question can be found here.

My solution is as follows:

int hammingDistance(int x, int y)
{
  int result = 0;
  int x_remainder = 0, y_remainder =0;
  while(x != 0 || y != 0)
    {
      x_remainder = x % 2;
      y_remainder = y % 2;
      if(x_remainder != y_remainder)
        ++result;
      x = x/2;
      y = y/2;
    }
  return result;
}

464 thoughts on “leetcode 461. Hamming Distance”

  1. Svenja holds a PhD from the University of St Andrews, an MSc from the Centre for Human Ecology/ University of Strathclyde, and an MA in Anthropology and Philosophy from the University of Glasgow. buy viagra There are no true natural alternatives to , like , but even Viagra is not safe for everyone.

Leave a Reply

Your email address will not be published. Required fields are marked *