class Solution { public: int calPoints(vector<string>& ops) { vector<int> v; for (auto &s : ops) { if (s == "+") { v.push_back(v[v.size()-1] + v[v.size()-2]); } else if (s == "D") { v.push_back(v.back() * 2); } else if (s == "C") { v.pop_back(); } else v.push_back(stoi(s)); } int res = 0; for (auto i : v) res += i; return res; } };