Skip to content

Commit 0b46607

Browse files
committed
solved: 461. Hamming Distance
Signed-off-by: rajput-hemant <[email protected]>
1 parent 0401d79 commit 0b46607

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
impl Solution {
2+
pub fn hamming_distance(x: i32, y: i32) -> i32 {
3+
let (mut x, mut y) = (x, y);
4+
let mut count = 0;
5+
6+
while x != 0 || y != 0 {
7+
if x % 2 != y % 2 {
8+
count += 1;
9+
}
10+
x /= 2;
11+
y /= 2;
12+
}
13+
14+
count
15+
}
16+
}

0 commit comments

Comments
 (0)