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

Commit 468e52d

Browse files
committed
fix
1 parent 98d860b commit 468e52d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kamyu104/src/hamming_distance.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ impl Solution1 {
1717
pub struct Solution2 {}
1818
impl Solution2 {
1919
pub fn hamming_distance(x: i32, y: i32) -> i32 {
20-
2
20+
let z = format!("{:b}", x ^ y);
21+
z.chars().filter(|&c| c == '1').count() as i32
2122
}
2223
}
2324

@@ -28,5 +29,6 @@ mod tests {
2829
#[test]
2930
fn test_hamming_distance() {
3031
assert_eq!(Solution1::hamming_distance(1, 4), 2);
32+
assert_eq!(Solution2::hamming_distance(1, 4), 2);
3133
}
3234
}

0 commit comments

Comments
 (0)