Simple Java Solution


  • 0
    C
    class Solution {
        public int hammingDistance(int x, int y) {
            int count = 0;
            while(x!=0 || y!=0){
                int a = x%2;
                int b = y%2;
                if(a!=b) count++;
                x = x/2;
                y = y/2;
            } 
            return count;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.