Decrypt String from Alphabet to Integer Mapping LeetCode solution in Rust

1
impl Solution {
2
pub fn freq_alphabets(s: String) -> String {
3
let mut iter = s.chars().rev().peekable();
4
let mut res = String::new();
5
loop {
6
match iter.next() {
7
Some('#') => {
8
let c1 = iter.next().unwrap().to_digit(10).unwrap() as u8;
9
let c2 = iter.next().unwrap().to_digit(10).unwrap() as u8;
10
res.push((c2 * 10 + c1 - 1 + 'a' as u8) as char)
11
}
12
Some(x) => {
13
let c = x.to_digit(10).unwrap() as u8;
14
res.push((c - 1 + 'a' as u8) as char);
15
}
16
_ => {}
17
}
18
if iter.peek() == None {
19
break;
20
}
21
}
22
res.chars().rev().collect()
23
}
24
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0