Skip to content

Commit 0a9c3ef

Browse files
committed
Runtime 0 ms (Top 100.0%) | Memory 39.0 MB (Top 26.44%)
1 parent 29ccfec commit 0a9c3ef

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
// Runtime: 1 ms (Top 45.03%) | Memory: 40.9 MB (Top 59.95%)
21
class Solution {
32
public int hammingDistance(int x, int y) {
4-
int n = x^y;
5-
int ans = 0;
6-
7-
// Run loop till n does not contain any 1
8-
while(n != 0){
9-
ans = ans + (n &1);
10-
n >>>= 1;
3+
int ans=x^y;
4+
int count=0;
5+
while(ans>0){
6+
count+=ans&1;
7+
ans>>=1;
118
}
12-
return ans;
9+
10+
return count;
1311
}
1412
}

0 commit comments

Comments
 (0)