Solution by bitset


  • 0
    S

    class Solution {
    public:
    int hammingDistance(int x, int y) {
    string a=bitset<32>(x).to_string();
    string b=bitset<32>(y).to_string();
    int dem=0;
    for(int i=0;i<32;i++)
    {
    if(a[i]!=b[i])
    dem++;
    }
    return dem;
    }
    };


Log in to reply
 

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