Skip to content

Commit df847a0

Browse files
authored
Merge pull request neetcode-gh#1645 from AkifhanIlgaz/0682
Create: 0682-baseball-game.rs
2 parents a1a0fff + ed97885 commit df847a0

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

rust/0682-baseball-game.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)