class Solution {
public:
int evalRPN(vector<string>& tokens) {
stack<int> st;
for(int i=;i < tokens.size();i++){
char temp = tokens[i][tokens[i].size()-];
if(temp >= '' && temp <= ''){
st.push(trams(tokens[i]));
}
else{
int a = st.top();
st.pop();
int b = st.top();
st.pop();
int res = ;
if(tokens[i] == "+") res = a+b;
if(tokens[i] == "-") res = b-a;
if(tokens[i] == "*") res = a*b;
if(tokens[i] == "/") res = b/a;
st.push(res);
}
}
return st.top();
}
int trams(string s){
int res = ;
int flag = ;
int j = ;
if(s[] == '-'){
flag = ;
j = ;
}
for(int i=j;i < s.size();i++){
char temp = s[i];
res = res* + (temp-'');
}
if(flag == ) res = -res;
return res;
}
};

字符串string几大坑人之处:1. 必须要用char = s[0]才能进行比较和变数字(char - '0')

              2.s == " " (双冒号) s[0] == ' ' (单冒号)

Leetcode 150的更多相关文章

  1. LeetCode 150. 逆波兰表达式求值(Evaluate Reverse Polish Notation) 24

    150. 逆波兰表达式求值 150. Evaluate Reverse Polish Notation 题目描述 根据逆波兰表示法,求表达式的值. 有效的运算符包括 +, -, *, /.每个运算对象 ...

  2. LeetCode——150. Evaluate Reverse Polish Notation

    一.题目链接:https://leetcode.com/problems/evaluate-reverse-polish-notation/ 二.题目大意: 给定后缀表达式,求出该表达式的计算结果. ...

  3. [LeetCode] 150. Evaluate Reverse Polish Notation 计算逆波兰表达式

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  4. Java实现 LeetCode 150 逆波兰表达式求值

    150. 逆波兰表达式求值 根据逆波兰表示法,求表达式的值. 有效的运算符包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰表达式. 说明: 整数除法只保留整数部分. 给定逆波 ...

  5. Java for LeetCode 150 Evaluate Reverse Polish Notation

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  6. leetcode 150. Evaluate Reverse Polish Notation ------ java

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  7. Leetcode#150 Evaluate Reverse Polish Notation

    原题地址 基本栈操作. 注意数字有可能是负的. 代码: int toInteger(string &s) { ; ] == '-' ? true : false; : ; i < s.l ...

  8. [leetcode]150. Evaluate Reverse Polish Notation逆波兰表示法

    Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...

  9. Leetcode 150.逆波兰表达式求值

    逆波兰表达式求值 根据逆波兰表示法,求表达式的值. 有效的运算符包括 +, -, *, / .每个运算对象可以是整数,也可以是另一个逆波兰表达式. 说明: 整数除法只保留整数部分. 给定逆波兰表达式总 ...

随机推荐

  1. 【C#】 Method invocation is skipped

    相信大家看到这个标题也是一头雾水了. 这个问题主要是我在项目中遇到了一个问题, 然后我通过搜索引擎搜索的关键词进而找到了answer, 我先描述一下我遇到的问题: 做项目的时候我发现log时常没有输出 ...

  2. js url参数和对象互转

    function param(a) { var s = [], rbracket = /\[\]$/, isArray = function(obj) { return Object.prototyp ...

  3. Linux安装Broadcom无线驱动

    参考https://blog.csdn.net/u012833250/article/details/52493806 首先查看自己的网卡型号,然后先执行sudo apt-get update 再根据 ...

  4. 【译】第17节---数据注解-Column

    原文:http://www.entityframeworktutorial.net/code-first/column-dataannotations-attribute-in-code-first. ...

  5. HDU 5782 Cycle(KMP+哈希)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5782 题意:给出两个长度相等的字符串,输出两个字符的每个前缀是否循环相同. 思路: 如果连个串循环相 ...

  6. Jquery loading 效果

    function showLoad(tipInfo) { var eTip = document.createElement('div'); eTip.setAttribute('id', 'tipD ...

  7. 利用React Native 从0到1 开发一款兼容IOS和android的APP(仿造京东)

    最近有一部电视剧叫做<微微一笑很傻逼>里面有个男猪脚,人们都叫他大神~我觉得吧~大神是相对的~所以~啥事都得谦虚! 好了 今天介绍的是如何从0到1利用React Native开发一款兼容I ...

  8. _itemmod_hidden

    该表中的物品放在背包或银行中中会计算属性 `entry`物品ID `comment` 备注

  9. pyqt 不规则形状窗口显示

    #coding=utf- import sys from PyQt5.QtCore import Qt from PyQt5.QtWidgets import QWidget, QApplicatio ...

  10. JVM(一)

    1 Java类加载器包括几种?它们之间的关系是怎么样的?双亲委派机制是什么意思?有什么好处? 启动Bootstrap类加载.扩展Extension类加载.系统System类加载. 类加载器也是Java ...