Bulls and Cows LeetCode solution in Rust

1
impl Solution {
2
pub fn get_hint(secret: String, guess: String) -> String {
3
let (mut a, mut b) = (0, 0);
4
let mut d1 = [0; 10];
5
let mut d2 = [0; 10];
6
for (s, g) in secret.as_bytes().iter().zip(guess.as_bytes()) {
7
if s == g {
8
a += 1;
9
} else {
10
d1[(s - b'0') as usize] += 1;
11
d2[(g - b'0') as usize] += 1;
12
}
13
}
14
for i in 0..10 {
15
b += std::cmp::min(d1[i], d2[i]);
16
}
17
format!("{}A{}B", a, b)
18
}
19
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0