原本以为要用queue就取叫q
写到一半发现是stack懒得改就继续q了
class Solution {
public:
int evalRPN(vector<string>& tokens) {
vector<int> q;
for(const string& t:tokens){
if(t=="+"){
int num1 = q.back();
q.pop_back();
int num2 = q.back();
q.pop_back();
q.push_back(num2+num1);
}
else if(t=="-"){
int num1 = q.back();
q.pop_back();
int num2 = q.back();
q.pop_back();
q.push_back(num2-num1);
}
else if(t=="*"){
int num1 = q.back();
q.pop_back();
int num2 = q.back();
q.pop_back();
q.push_back(num2*num1);
}
else if(t=="/"){
int num1 = q.back();
q.pop_back();
int num2 = q.back();
q.pop_back();
q.push_back(num2/num1);
}
else{
q.push_back(stoi(t));
}
}
return q[0];
}
};