We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
class Solution { public: int evalRPN(vector<string>& tokens) { stack<int> stack; int n = tokens.size(); for(int i=0;i<n;i++) { string s = tokens[i]; bool isOp = s == "+" || s == "-" || s == "*" || s == "/"; if (isOp) { int a = stack.top(); stack.pop(); int b = stack.top(); stack.pop(); if (s == "+") { stack.push(a + b); } else if(s == "-") { stack.push(b - a); } else if(s == "*"){ stack.push(a * b); } else { stack.push(b / a); } } else { stack.push(stoi(s)); } } return stack.top(); } };
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: