blob: 881d15a90fb9f164ea46fc4203991b190a2be776 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
fn main() {
println!("Hello, world!");
let tests = [
("a1c1e1", "abcdef"),
("a1b2c3d4e", "abbdcfdhe")
];
for (input, output) in tests {
let result = Solution::replace_digits(input.to_string());
println!("{input:?} is {result:?} should be {output:?}");
}
}
struct Solution;
impl Solution {
pub fn replace_digits(mut s: String) -> String {
unsafe {s.as_bytes_mut()}.chunks_exact_mut(2).for_each(|x| x[1] = x[0] + x[1] - b'0');
s
}
}
|