Decode String LeetCode solution in Rust

1
impl Solution {
2
pub fn decode_string(s: String) -> String {
3
let mut stack: Vec<(usize, String)> = Vec::new();
4
let (mut n, mut str) = (0, String::new());
5
for c in s.chars() {
6
match c {
7
'[' => {
8
stack.push((n, str.clone()));
9
n = 0;
10
str.clear();
11
}
12
']' => {
13
if let Some(last) = stack.pop() {
14
str = last.1 + str.repeat(last.0).as_str();
15
}
16
}
17
'0'..='9' => n = n * 10 + (c as u8 - b'0') as usize,
18
c => str.push(c),
19
}
20
}
21
str
22
}
23
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0