[LeetCode]Evaluate Reverse Polish Notation
来源:互联网 发布:淘宝打折活动名称 编辑:程序博客网 时间:2024/05/16 14:57
这道题主要难点是栈(stack)的使用。
#include <iostream>#include <string.h>#include <vector>#include <stack>using namespace std;class Solution {public:bool IsOp(string s){if (s == "+" || s == "-" || s == "*" || s == "/")return true;else return false;}int evalRPN(vector<string> &tokens) {vector<string>::iterator it;stack<int> s;int result = 0;for (it = tokens.begin(); it != tokens.end(); it++){int a;if (!IsOp(*it)){a = atoi((*it).data());s.push(a);}else{char op = (*it).data()[0];int a = s.top(); s.pop();int b = s.top(); s.pop();switch (op){case '+':result = b + a; break;case '-':result = b - a; break;case '*':result = b * a; break;case '/':result = b / a; break;default:break;}s.push(result);}}return s.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
- 清明时节雨纷纷 路上行人欲断魂v
- 电流(或电压)的平均值与有效值
- 换工作心得
- Android API Guides 之 App Resources(8) - Resource Types - Color
- STL序列式容器
- [LeetCode]Evaluate Reverse Polish Notation
- linux下iostat命令解析 (性能相关以及性能调试)
- 索引_建表:A表:集簇因子=块数;B表:集簇因子=行数
- notePad++配置C/C++编译运行环境
- 面试题5 从尾到头打印链表
- Eclipse离线安装ADT插件
- 安装Win7系统为硬盘分区的方法
- 李さんわ ちゅうごくじんです
- Android学习之Bitmap