We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent a237872 commit 1da56eaCopy full SHA for 1da56ea
00682. Baseball Game.rs
@@ -0,0 +1,27 @@
1
+impl Solution {
2
+ // Loop through ops, follow the instructions in a if-else blocks to create a final vec. Then loop through the final vec to calculate the result sum
3
+ pub fn cal_points(ops: Vec<String>) -> i32 {
4
+ let mut final_vec = Vec::new();
5
+ let mut sum = 0;
6
+
7
+ for op in ops {
8
+ let len = final_vec.len();
9
10
+ if op == "C" {
11
+ final_vec.pop();
12
+ } else if op == "D" {
13
+ final_vec.push(final_vec[len - 1] * 2);
14
+ } else if op == "+" {
15
+ final_vec.push(final_vec[len - 1] + final_vec[len - 2]);
16
+ } else {
17
+ final_vec.push(op.parse::<i32>().unwrap());
18
+ }
19
20
21
+ for num in final_vec {
22
+ sum += num;
23
24
25
+ return sum;
26
27
+}
0 commit comments