1) Create a stack to store the value / numbers.
2) Scan the given expression and do following for every scanned element.
a) If the element is a number, push it into the stack.
b) If the element is a operator,pop first two numbers from stack.
c) The 1st no is right operand and 2nd no is left.
c) Evaluate the operator and push the result back to the stack.
3) When the expression is ended, the number in the stack is the final answer.
classSolution{public:intevalRPN(vector<string> &tokens) { stack<int> s;for (int i =0; i <tokens.size(); i++) {if(tokens[i]=="+"||tokens[i]=="-"||tokens[i]=="*"||tokens[i]=="/") {int res;int r =s.top();s.pop();int l =s.top();s.pop();if (tokens[i] =="+") { res = l + r; }elseif (tokens[i] =="-") { res = l - r; }elseif (tokens[i] =="/") { res = l / r; }elseif (tokens[i] =="*") { res = l * r; }s.push(res); }else {int n =stoi(tokens[i]); //convert a string to intergers.push(n); } }returns.top(); }};