Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 018cd5c

Browse files
committed
fix
1 parent 8a134b0 commit 018cd5c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kamyu104/src/hamming_distance.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
pub struct Solution {}
44
impl Solution {
55
pub fn hamming_distance(x: i32, y: i32) -> i32 {
6-
2
6+
let mut distance: i32 = 0;
7+
let mut z: i32 = x ^ y;
8+
while z != 0 {
9+
distance += 1;
10+
z &= z - 1;
11+
}
12+
distance
713
}
814
}
915

@@ -16,4 +22,3 @@ mod tests {
1622
assert_eq!(Solution::hamming_distance(1, 4), 2);
1723
}
1824
}
19-

0 commit comments

Comments
 (0)