lintcode-逆波兰表达式求值-424
来源:互联网 发布:linux创建目录命令 编辑:程序博客网 时间:2024/05/21 09:42
求逆波兰表达式的值。
在逆波兰表达法中,其有效的运算符号包括 +
, -
,*
, /
。每个运算对象可以是整数,也可以是另一个逆波兰计数表达。
样例
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
class Solution {public: inline bool contains(string &s){ if(!s.compare("+")||!s.compare("-")||!s.compare("*")||!s.compare("/")) return false; return true; } inline int Pop(){ int tmp=s.top(); s.pop(); return tmp; } int evalRPN(vector<string>& tokens) { for(auto &e:tokens){ if(contains(e)){ s.push(stoi(e)); continue; } int a=Pop(); int b=Pop(); if(!e.compare("+")) s.push(b+a); else if(!e.compare("-")) s.push(b-a); else if(!e.compare("*")) s.push(b*a); else s.push(b/a); } return s.top(); }private: stack<int> s; };
0 0
- lintcode-逆波兰表达式求值-424
- LintCode 424-逆波兰表达式求值
- lintcode-逆波兰表达式求值-424
- LintCode : 逆波兰表达式求值
- LintCode:逆波兰表达式求值
- Lintcode 逆波兰表达式求值
- lintcode--逆波兰表达式求值
- Lintcode 逆波兰表达式求值
- 逆波兰表达式求值-LintCode
- LintCode:M-逆波兰表达式求值
- 【LintCode】Evaluate Reverse Polish Notation 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 逆波兰表达式求值
- 起个名字好难:关于变量命名的思考与总结
- 归并排序
- android studio的一些编译错误
- Selenium+PhantomJS 爬取页面
- POJ 2965 The Pilots Brothers' refrigerator 枚举dfs
- lintcode-逆波兰表达式求值-424
- qt获取当前时间以及日期
- POJ 1014 && HDU 1059 Dividing(完全背包问题)
- Android中创建AIDL服务的步骤
- Java 的布局管理器GridBagLayout的使用方法【图文说明】
- [234]Palindrome Linked List
- c++ primer学习笔记3_复合类型
- 如何使用Android Studio把自己的Android library分享到jCenter和Maven Central
- ***6.22-八皇后问题