We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a1a0fff + ed97885 commit df847a0Copy full SHA for df847a0
rust/0682-baseball-game.rs
@@ -0,0 +1,27 @@
1
+impl Solution {
2
+ pub fn cal_points(operations: Vec<String>) -> i32 {
3
+ let mut points: Vec<i32> = Vec::new();
4
+
5
+ for op in operations {
6
+ match &op[..] {
7
+ "D" => {
8
+ let new_point = points.last().unwrap();
9
+ points.push(*new_point * 2);
10
+ }
11
12
+ "C" => {
13
+ points.pop();
14
15
+ "+" => {
16
+ let len = points.len();
17
+ points.push(points[len - 1] + points[len - 2]);
18
19
+ _ => {
20
+ points.push(op.parse::<i32>().unwrap());
21
22
23
24
25
+ points.iter().sum()
26
27
+}
0 commit comments