class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tokens string字符串vector * @return int整型 */ int evalRPN(vector<string> &tokens) { // write code here vector<int> mStack; for (int i = 0; i < tokens.size(); i++) { string s = tokens[i]; if (isOp(s)) { int b = mStack.back(); mStack.pop_back(); int a = mStack.back(); mStack.pop_back(); if (s == "+") { mStack.push_back(a + b); } else if (s == "-") { mStack.push_back(a - b); } else if (s == "*") { mStack.push_back(a * b); } else if (s == "/") { mStack.push_back(a / b); } else { } } else{ int num = stoi(s); mStack.push_back(num); } } return mStack.back(); } //判断是否是操作符 bool isOp(string s) { if (s == "+" || s == "-" || s == "*" || s == "/")return true; return false; } };