执行用时 : 0 ms, 在Hamming Distance的C++提交中击败了100.00% 的用户

内存消耗 : 8.3 MB, 在Hamming Distance的C++提交中击败了73.26% 的用户

class Solution {
public:
    int hammingDistance(int x, int y) {
        int t=x^y;
        return gethan(t);
    }
    int gethan(int x)
    {
        int k=0;
        while(x>0)
        {
            if((x&1)==1)
            {
                k++;
            }
            x=x>>1;
        }
        return k;
    }
};

 


版权声明:本文为qq_38346791原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_38346791/article/details/90443904