-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBaseball Game
34 lines (33 loc) · 992 Bytes
/
Baseball Game
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Solution {
public int calPoints(String[] ops) {
LinkedList<Integer> list = new LinkedList<>();
int sum = 0;
for(var op : ops){
switch (op){
case "C":{
sum -= list.removeLast();
//list.removeLast();
break;
}
case "D":{
int item = list.getLast();
list.addLast(item*2);
sum+=item*2;
break;
}
case "+":{
int value = list.get(list.size()-2)+list.getLast();
list.addLast(value);
sum+=value;
break;
}
default:{
list.addLast(Integer.parseInt(op));
sum+=Integer.parseInt(op);
break;
}
}
}
return sum;
}
}