链接: link

using namespace std;
class Solution {
public:
int evalRPN(vector<string>& tokens) {
stack <int> a;
for (auto& b : tokens)
{
if (b == "+")//如何操作str!=char??
{
int right = a.top();
a.pop();
int left = a.top();
a.pop();
a.push(right + left);
}
else if (b == "-")//如何操作str!=char??
{
int right = a.top();
a.pop();
int left = a.top();
a.pop();
a.push(left - right);
}
else if (b == "*")//如何操作str!=char??
{
int right = a.top();
a.pop();
int left = a.top();
a.pop();
a.push(right * left);
}
else if (b == "/")//如何操作str!=char??
{
int right = a.top();
a.pop();
int left = a.top();
a.pop();
a.push(left / right);
}
else
{
a.push(stoi(b));
}
}
return a.top();
}
};
263

被折叠的 条评论
为什么被折叠?



