my code


  • 0
    R

    public class Solution {
    public int hammingDistance(int x, int y) {

        int sum = 0;
        while(x != 0 ||  y != 0){
            
            if(x % 2 == 1 && y % 2 == 0){
                sum = sum + 1;
            }
            else if(x % 2 == 0 && y % 2 == 1){
                sum = sum + 1 ;
            }
            x = x/2;
            y = y/2;
            //if(x == 0 && y == 0){
              //  break;
            //}
            
        }
        
        
        
        return sum;
        
        
        
        
    }
    

    }


Log in to reply
 

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