-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathBaseball Game
More file actions
31 lines (31 loc) · 792 Bytes
/
Copy pathBaseball Game
File metadata and controls
31 lines (31 loc) · 792 Bytes
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
class Solution {
public:
int calPoints(vector<string>& ops) {
int temp = 0;
stack<int> record;
for(int i=0;i<ops.size();i++){
if(ops[i] == "C"){
record.pop();
}
else if(ops[i] == "D"){
record.push(2*record.top());
}
else if(ops[i] == "+"){
temp = record.top();
record.pop();
int val = temp + record.top();
record.push(temp);
record.push(val);
}
else{
record.push(stoi(ops[i]));
}
}
int sum =0;
while(!record.empty()){
sum += record.top();
record.pop();
}
return sum;
}
};