MCPcopy Create free account
hub / github.com/StudyRust/leetcode_rust / hamming_distance

Function hamming_distance

461-hamming-distance.rs:23–35  ·  view source on GitHub ↗
(x: i32, y: i32)

Source from the content-addressed store, hash-verified

21}
22
23pub fn hamming_distance(x: i32, y: i32) -> i32 {
24 let x = format!("{:#064b}", x);
25 let y = format!("{:#064b}", y);
26 let x_chars: Vec<char> = x.chars().collect(); // i32 转 2进制string 转 Vec<char> 才好处理
27 let y_chars: Vec<char> = y.chars().collect();
28 let mut counter = 0;
29 for i in 0..64 {
30 if x_chars[i] != y_chars[i] {
31 counter += 1;
32 }
33 }
34 counter
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected