原题地址

基本栈操作。

注意数字有可能是负的。

代码:

 int toInteger(string &s) {
int res = ;
bool negative = s[] == '-' ? true : false; for (int i = negative ? : ; i < s.length(); i++) {
res *= ;
res += s[i] - '';
}
return negative ? -res : res;
} int compute(int a, int b, string sign) {
switch (sign[]) {
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
return -;
}
} int evalRPN(vector<string> &tokens) {
stack<int> st; for (auto t : tokens) {
if (t.length() > || t[] >= '' && t[] <= '')
st.push(toInteger(t));
else {
int b = st.top();
st.pop();
int a = st.top();
st.pop();
st.push(compute(a, b, t));
}
} return st.top();
}

Leetcode#150 Evaluate Reverse Polish Notation的更多相关文章

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

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

  2. Java for LeetCode 150 Evaluate Reverse Polish Notation

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

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

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

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

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

  5. LeetCode——150. Evaluate Reverse Polish Notation

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

  6. 【LeetCode】150. Evaluate Reverse Polish Notation 解题报告(Python)

    [LeetCode]150. Evaluate Reverse Polish Notation 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/ ...

  7. 150. Evaluate Reverse Polish Notation - LeetCode

    Question 150. Evaluate Reverse Polish Notation Solution 2 1 + 3 * 是((2+1)*3)的后缀(postfix)或逆波兰(reverse ...

  8. 【LeetCode】150. Evaluate Reverse Polish Notation

    Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...

  9. 【刷题-LeetCode】150 Evaluate Reverse Polish Notation

    Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...

随机推荐

  1. project 2010 使用技巧

    快捷键 设置任务子任务 ALT+SHIFT+向右方向键 1.工作时间设置 新建一个日历后,可以在 “项目 >> 项目信息 >> 日历” 中进行选择

  2. 封装Html5 Fullscreen API

    复制前言: 使用新的全屏 API,可以将用户的注意力导向特定元素,同时隐藏背景或转移对其他应用的注意力.因为W3C全屏规范还未达到最终版本,所以大多数浏览器供应商都使用唯一标识符为 API 添加前缀. ...

  3. 【Weblogic】--Weblogic的部署方式和缓存

    参考网址: http://dead-knight.iteye.com/blog/1938882 Weblogic11g部署web应用,有三种方式,非常简单,但是很多新手部署总是出现若干错误,不知道如何 ...

  4. Jquery在项目中的总结

    1.构造对象 var _getSearchArg = function () { var argModel = {}; argModel.Txt = value; argModel.Code = va ...

  5. Jquery制作可以绑定的表格

    //总页数 当前页 可见页 参数 翻页执行后处理的函数 function PageTable(totalPages, currentPage, tableobj, url, where, column ...

  6. LinearRegressionWithRegularization

    在线性回归的基础上加上正则项: # -*-coding:utf-8 -*- ''' Created on 2016年12月15日 @author: lpworkdstudy ''' import nu ...

  7. ListView用法及加载数据时的闪烁问题和加载数据过慢问题

    ListView介绍及添加数据时的闪烁问题 1.     ListView类 1.1 ListView常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示 ...

  8. java读取各类型的文件

    java读取各类型的文件 用到的几个包 bcmail-jdk14-132.jar/bcprov-jdk14-132.jar/checkstyle-all-4.2.jar/FontBox-0.1.0-d ...

  9. [原创]从Oracle和Microsoft Sql Server迁移到PostgreSQL Plus Advanced Server

    一.了解PPAS的迁移方式1.在线迁移和离线迁移使用Migration Studio或Migration Toolkit直接向PPAS数据库进行对象定义和数据表中数据的迁移称为在线迁移,生成要迁移对象 ...

  10. malloc calloc realloc,new区别联系以及什么时候用

    三个函数的申明分别是:void* realloc(void* ptr, unsigned newsize);void* malloc(unsigned size);void* calloc(size_ ...