Leetcode Evaluate Reverse Polish Notation
来源:互联网 发布:linux ndk 编译的so 编辑:程序博客网 时间:2024/06/01 08:07
题意:后序运算。
思路:使用堆栈储存操作对象。
class Solution {public: stack<int> ms; int evalRPN(vector<string>& tokens) { for(int i = 0; i < tokens.size(); ++ i) { if(tokens[i][0] == '+' && tokens[i].length() == 1) { int a = ms.top(); ms.pop(); int b = ms.top(); ms.pop(); ms.push(b + a); } else if (tokens[i][0] == '-' && tokens[i].length() == 1) { int a = ms.top(); ms.pop(); int b = ms.top(); ms.pop(); ms.push(b - a); } else if (tokens[i][0] == '*' && tokens[i].length() == 1) { int a = ms.top(); ms.pop(); int b = ms.top(); ms.pop(); ms.push(b * a); } else if (tokens[i][0] == '/' && tokens[i].length() == 1) { int a = ms.top(); ms.pop(); int b = ms.top(); ms.pop(); ms.push(b / a); } else ms.push(std::stoi(tokens[i])); } return ms.top(); }};
0 0
- Evaluate Reverse Polish Notation | leetcode
- leetcode-Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- LeetCode - Evaluate Reverse Polish Notation
- LeetCode | Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- Leetcode: Evaluate Reverse Polish Notation
- Evaluate Reverse Polish Notation (LeetCode)
- leetcode: Evaluate Reverse Polish Notation
- Leetcode Evaluate Reverse Polish Notation
- [LeetCode] Evaluate Reverse Polish Notation
- [LeetCode] Evaluate Reverse Polish Notation
- Evaluate Reverse Polish Notation -- LeetCode
- 【LeetCode】Evaluate Reverse Polish Notation
- LeetCode-Evaluate Reverse Polish Notation
- LeetCode:Evaluate Reverse Polish Notation
- LeetCode Evaluate Reverse Polish Notation
- Leetcode:Evaluate Reverse Polish Notation
- C++类对象共享数据的两种实现方法
- bias and variance
- Unity-android Remote 测试
- github 传输速度慢解决方法
- 二进制最大公约数算法
- Leetcode Evaluate Reverse Polish Notation
- JavaScript 运动框架 Step by step
- 用photoshop结合切片工具处理超级大图,例如原图为完整的台湾省19级图片
- Linux设备驱动第六天(工作队列、定时器、延时)
- 切面条(大数据处理)
- Sql — CTE公用表表达式和With用法总结
- bukket插件例子(4)代码分析
- 诊断硬盘狂读的经验
- 12.13 二维特殊图形函数