150. Evaluate Reverse Polish Notation
来源:互联网 发布:mac如何合上盖子不休眠 编辑:程序博客网 时间:2024/06/08 06:43
//16ms acclass Solution {public: int atoi(string s) { int i=0,l=1,r=0; bool flag=false; if(s[0]=='-') { r=1; flag=true; } for(int j=s.size()-1;j>=r;j--) { i+=(s[j]-'0')*l; l*=10; } if(flag) return 0-i; return i; } int evalRPN(vector<string>& tokens) { stack<int> s; s.push(atoi(tokens[0])); int i=1; while(i<=tokens.size()-1) { if(tokens[i]=="+") { int a=s.top(); s.pop(); int b=s.top(); s.pop(); s.push(a+b); } else if(tokens[i]=="-") { int a=s.top(); s.pop(); int b=s.top(); s.pop(); s.push(b-a); } else if(tokens[i]=="*") { int a=s.top(); s.pop(); int b=s.top(); s.pop(); s.push(b*a); } else if(tokens[i]=="/") { int a=s.top(); s.pop(); int b=s.top(); s.pop(); s.push(b/a); } else s.push(atoi(tokens[i])); i++; } return s.top(); }};
0 0
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- 150. Evaluate Reverse Polish Notation
- Unable to execute dex: Cannot merge new index 66827 into a non-jumbo instruction!
- hibernate实现多表联合查询
- c++作业3
- UVA 1149 Bin Packing 装箱 经典贪心 (SWERC 2005)
- 安装软件
- 150. Evaluate Reverse Polish Notation
- <mvc:resources> 标签的使用
- 我开博客了
- 开关和灯
- APP的开发模式:Native App、Web App、Hybrid App三种开发模式
- 新正方教务系统无需验证码即可模拟登陆
- HDOJ 3072 Intelligence System
- UTC时间的转换
- HDU-1039-Easier Done Than Said?