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