-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path461.cpp
35 lines (35 loc) · 961 Bytes
/
461.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
__________________________________________________________________________________________________
sample 4 ms submission
class Solution {
public:
int hammingDistance(int x, int y) {
int res = 0;
for (int i = 0; i < 32; ++i) {
if ((x & (1 << i)) ^ (y & (1 << i))) {
++res;
}
}
return res;
}
};
__________________________________________________________________________________________________
sample 8200 kb submission
static const auto _____ = []()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
return nullptr;
}();
class Solution {
public:
int hammingDistance(int x, int y) {
unsigned int hamming = x^y;
int counter=0;
while(hamming){
counter+=(hamming&1);
hamming>>=1;
}
return counter;
}
};
__________________________________________________________________________________________________