-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path682.cpp
More file actions
31 lines (31 loc) · 724 Bytes
/
682.cpp
File metadata and controls
31 lines (31 loc) · 724 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) {
stack<int> res;
for(auto t: ops){
if(t=="+"){
int b = res.top();res.pop();
int a = res.top();
int r = a + b;
res.push(b);
res.push(r);
}
else if(t=="D"){
int tmp = res.top();
res.push(2*tmp);
}
else if(t=="C"){
res.pop();
}
else{
res.push(stoi(t));
}
}
int ans = 0;
while(!res.empty()){
ans += res.top();
res.pop();
}
return ans;
}
};