-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathBaseball Game.cpp
More file actions
40 lines (39 loc) · 834 Bytes
/
Baseball Game.cpp
File metadata and controls
40 lines (39 loc) · 834 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
32
33
34
35
36
37
38
39
40
class Solution {
public:
int calPoints(vector<string>& ops)
{
int value1;
int value2;
int ans = 0;
stack<int>stk;
for(string i:ops)
{
if(i == "C")
{
stk.pop();
}
else if(i == "D")
{
stk.push(stk.top()*2);
}
else if(i == "+")
{
value1 = stk.top();
stk.pop();
value2 = stk.top();
stk.push(value1);
stk.push(value1 + value2);
}
else
{
stk.push(stoi(i));
}
}
while(stk.size() != 0)
{
ans += stk.top();
stk.pop();
}
return ans;
}
};