Baseball Game LeetCode solution in C++
1class Solution {2public:3int calPoints(vector<string> &ops) {4stack<int> st;5int n = ops.size();6for (int i = 0; i < n; i++) {7if (ops[i] == "C") {8st.pop();9} else if (ops[i] == "D") {10st.push(st.top() * 2);11} else if (ops[i] == "+") {12int temp = st.top();13st.pop();14int temp2 = st.top();15st.push(temp);16st.push(temp + temp2);17} else {18st.push(stoi(ops[i]));19}20}21int res = 0;22while (!st.empty()) {23res += st.top();24st.pop();25}26return res;27}28};