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

Function di_string_match

942-di-string-match.rs:1–17  ·  view source on GitHub ↗
(s: String)

Source from the content-addressed store, hash-verified

1pub fn di_string_match(s: String) -> Vec<i32> {
2 let s_len = s.len();
3 let mut arr: Vec<i32> = (0..s_len+1).map(|e|e as i32).collect();
4 let mut res: Vec<i32> = vec!();
5 for c in s.chars() {
6 let op_index;
7 if c == 'I' {
8 op_index = 0;
9 } else {
10 op_index = arr.len()-1;
11 }
12 res.push(arr[op_index]);
13 arr.remove(op_index);
14 }
15 res.push(*arr.last().unwrap());
16 res
17}
18
19fn main() {
20 println!("{:?}", di_string_match("IDID".to_string()));

Callers

nothing calls this directly

Calls 2

pushMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected