topic
![Here Insert Picture Description](https://img-blog.csdnimg.cn/20200323005157962.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1BhbmdfbGluZw==,size_16,color_FFFFFF,t_70)
Add a link description
Problem-solving ideas
- The former through the array backwards
- Digital encounter is pushed onto the stack
- The first two characters meet the top of the stack will be calculated symbol calculation result together with the stack
- Through the array in the end, the top element is the final answer
public class Solution {
public int EvalRPN(string[] tokens) {
Stack<int> data = new Stack<int>();
for (int i = 0; i < tokens.Length; i++)
{
if (tokens[i] == "+" || tokens[i] == "/" || tokens[i] == "-" || tokens[i] == "*")
{
int a = data.Pop();
int b = data.Pop();
if (tokens[i] == "+")
{
data.Push(b + a);
}
if (tokens[i] == "-")
{
data.Push(b - a);
}
if (tokens[i] == "*")
{
data.Push(b * a);
}
if (tokens[i] == "/")
{
data.Push(b / a);
}
}
else
data.Push(int.Parse(tokens[i]));
}
return data.Pop();
}
}
![Here Insert Picture Description](https://img-blog.csdnimg.cn/2020032412363239.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L1BhbmdfbGluZw==,size_16,color_FFFFFF,t_70)