My code in java


  • 0
    D

    My code in java

    class Solution {
        public int hammingDistance(int x, int y) {
        int a[]=new int[32];
        int b[]=new int[32];
            int count=0;
            
        for(int i=31;i>=0;i--)
        {
            a[i]=x%2;
            x=x/2;
            b[i]=y%2;
            y=y/2;
            if(a[i]!=b[i])
            {
                count++;
            }
        }
            return count;
        }
    }
    

Log in to reply
 

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