LeetCode(150) Evaluate Reverse Polish Notation
来源:互联网 发布:淘宝的旗舰店可信吗 编辑:程序博客网 时间:2024/04/30 01:42
栈
class Solution {public: int evalRPN(vector<string>& tokens) { stack<string> stringStack; int xiaoshu; int dashu; for(int i = 0; i < tokens.size(); i++) { if(tokens[i] != "+" && tokens[i] != "-" && tokens[i] != "*" && tokens[i] != "/") { stringStack.push(tokens[i]); }else { xiaoshu = std::stoi(stringStack.top()); stringStack.pop(); dashu = std::stoi(stringStack.top()); stringStack.pop(); if(tokens[i] == "+") stringStack.push(std::to_string(dashu + xiaoshu)); if(tokens[i] == "-") stringStack.push(std::to_string(dashu - xiaoshu)); if(tokens[i] == "*") stringStack.push(std::to_string(dashu * xiaoshu)); if(tokens[i] == "/") stringStack.push(std::to_string(dashu / xiaoshu)); } } return std::stoi(stringStack.top()); }};
0 0
- LeetCode 150 Evaluate Reverse Polish Notation
- LeetCode: Evaluate Reverse Polish Notation [150]
- LeetCode(150) Evaluate Reverse Polish Notation
- [leetcode 150] Evaluate Reverse Polish Notation
- [LeetCode 150]Evaluate Reverse Polish Notation
- Leetcode 150:Evaluate Reverse Polish Notation
- Evaluate Reverse Polish Notation - LeetCode 150
- LeetCode---(150)Evaluate Reverse Polish Notation
- [Leetcode 150, Medium] Evaluate Reverse Polish Notation
- leetcode[150]:Evaluate Reverse Polish Notation
- LeetCode(150) Evaluate Reverse Polish Notation
- [leetcode-150]Evaluate Reverse Polish Notation(c++)
- leetcode 150: Evaluate Reverse Polish Notation
- 【leetcode】No.150 Evaluate Reverse Polish Notation
- LeetCode(150) Evaluate Reverse Polish Notation
- LeetCode 150 Evaluate Reverse Polish Notation
- leetcode(150):Evaluate Reverse Polish Notation
- Leetcode 150 Evaluate Reverse Polish Notation
- HDU 2952 Counting Sheep (DFS)
- 一个Web布局实例
- 验证数学黑洞 ,用户输入一个四位数,输出变换到6174的过程
- javascript之变量
- Java小日历
- LeetCode(150) Evaluate Reverse Polish Notation
- Delphi学习第三天
- Mysql中创建用户和授权的方法
- c++类类型的一个问题!
- Web_url
- 【计蒜客系列】挑战难题21:最大子阵列
- leetcode之路008 String to Integer (atoi)
- sift是图像匹配的非常经典的算法
- 漫水填充算法的一个简单实现(Qt版)