blob: f5d1b3597db9b9a871cfc3edcb68c56853121e1a (
plain)
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
|
#include "leetcode.h"
class Solution {
public:
int calPoints(vector<string> &ops) {
int val1, val2, ans = 0;
stack<int> s;
for (string i : ops) {
if (i == "C")
s.pop();
else if (i == "D")
s.push(s.top() * 2);
else if (i == "+") {
val1 = s.top();
s.pop();
val2 = s.top();
s.push(val1);
s.push(val1 + val2);
} else
s.push(stoi(i));
}
while (s.size() != 0) {
ans += s.top();
s.pop();
}
return ans;
}
};
int main() {}
|