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

Function cal_points

682-baseball-game.rs:1–18  ·  view source on GitHub ↗
(ops: Vec<String>)

Source from the content-addressed store, hash-verified

1pub fn cal_points(ops: Vec<String>) -> i32 {
2 let mut arr = vec!();
3 for e in ops {
4 if e == "C".to_string() {
5 arr.pop();
6 } else if e == "D".to_string() {
7 let tmp = arr.iter().last().unwrap() * 2;
8 arr.push(tmp);
9 } else if e == "+".to_string() {
10 let start = &arr.len() - 2;
11 arr.push(arr[start..].iter().sum::<i32>());
12 } else {
13 let num: i32 = e.parse().unwrap();
14 arr.push(num);
15 }
16 }
17 arr.iter().sum()
18}
19
20fn main() {
21 let ops = vec!["5","-2","4","C","D","9","+","+"].iter().map(|e|e.to_string()).collect();

Callers

nothing calls this directly

Calls 3

sumMethod · 0.80
popMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected