using right shift simple c++ solution


  • 0
    A
    class Solution {
    public:
        int hammingDistance(int x, int y) {
                    int i = 0;
    		int cnt = 0;
    		while (i<32) {	
                       if ((x&1)^(y&1)) {
    		       cnt++;
    		   }
    		     x>>=1;
    		     y>>=1;
    		     i++;
    		}
    		return cnt;
        }
    };
    

Log in to reply
 

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