Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are +
, -
, *
, /
. Each operand may be an integer or another expression.
Some examples:
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6
Subscribe to see which companies asked this question
解答:
这道题只要注意有负数就可以了。
int evalRPN(char** tokens, int tokensSize) { int stack[tokensSize]; , sum, i, j; ; i < tokensSize; i++){ '){ sum = ; ; tokens[i][j] != ; j++){ sum = sum * + tokens[i][j] - '; } stack[++top] = sum; } else{ if('+' == *(tokens[i])){ stack[top - ] = stack[top - ] + stack[top]; } else if('-' == *(tokens[i])){ == tokens[i][]) stack[top - ] = stack[top - ] - stack[top]; else{ sum = ; ; tokens[i][j] != ; j++){ sum = sum * + tokens[i][j] - '; } stack[++top] = -sum; continue; } } else if('*' == *(tokens[i])){ stack[top - ] = stack[top - ] * stack[top]; } else if('/' == *(tokens[i])){ stack[top - ] = stack[top - ] / stack[top]; } top--; } } return stack[top]; }
LeetCode OJ 150. Evaluate Reverse Polish Notation的更多相关文章
-
【LeetCode】150. Evaluate Reverse Polish Notation 解题报告(Python)
[LeetCode]150. Evaluate Reverse Polish Notation 解题报告(Python) 标签: LeetCode 题目地址:https://leetcode.com/ ...
-
【LeetCode】150. Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...
-
【刷题-LeetCode】150 Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...
-
LeetCode OJ:Evaluate Reverse Polish Notation(逆波兰表示法的计算器)
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
-
【LeetCode OJ】Evaluate Reverse Polish Notation
Problem link: http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/ According to the wik ...
-
【LeetCode练习题】Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation Evaluate the value of an arithmetic expression in Reverse Polish No ...
-
[LeetCode] 150. Evaluate Reverse Polish Notation 计算逆波兰表达式
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
-
Java for LeetCode 150 Evaluate Reverse Polish Notation
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
-
leetcode 150. Evaluate Reverse Polish Notation ------ java
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, ...
随机推荐
-
2016/12summary
应用服务器处理业务逻辑,web服务器处理html文件.web服务器更加简单.应用服务器有tomcat,jboss,weblogic,web服务器有IIS,Apache. 徐总:core里面做业务逻辑, ...
-
[软件测试]Linux环境中简单清爽的Google Test (GTest)测试环境搭建(初级使用)
本文将介绍单元测试工具google test(GTEST)在linux操作系统中测试环境的搭建方法.本文属于google test使用的基础教程.在linux中使用google test之前,需要对如 ...
-
JS常用的设计模式(11)—— 中介者模式
中介者对象可以让各个对象之间不需要显示的相互引用,从而使其耦合松散,而且可以独立的改变它们之间的交互. 打个比方,军火买卖双方为了安全起见,找了一个信任的中介来进行交易.买家A把钱交给中介B,然后从中 ...
-
BBSXP最新漏洞 简单注入检測 万能password
BBSXP最新漏洞 漏洞日期:2005年7月1日受害版本号:眼下全部BBSXP漏洞利用:查前台password注入语句:blog.asp?id=1%20union%20select%201,1,use ...
-
C:\WINDOWS\system32\drivers\etc\hosts host文件夹里面的内容是什么?
这个文件是根据TCP/IP for Windows 的标准来工作的,它的作用是包含IP地址和Host name(主机名)的映射关系,是一个映射IP地址和Host name(主机名)的规定,规定要求每段 ...
-
Linux入门基础 #10:命令行文本处理工具
本文出自 http://blog.****.net/shuangde800 ------------------------------------------------------------ ...
-
Prometheus安装和配置node_exporter监控主机
Node_exporter是可以在* Nix和Linux系统上运行的计算机度量标准的导出器. Node_exporter 主要用于暴露 metrics 给 Prometheus,其中 metrics ...
-
记录flask使用模板时出现的“Internal Server Error”错误
在看<Flask Web开发实战:入门.进阶与原理解析(李辉著 )>时照着书上的代码抄了一遍,然后运行时发现一直出现以下的错误 书上的源代码如下 watchlist.html <he ...
-
luogu1941 [NOIp2014]飞扬的小鸟 (dp)
设f[i][j]为到达(i,j)这个位置的最小操作数 就有$f[i][j]=min\{f[i-1][j+Y[i-1]],f[i-1][j-X[i-1]*k]+k\}$ 然后考虑优化一下转移: 对于一系 ...
-
python之模块contextlib 加强with语句而存在
# -*- coding: utf-8 -*- #python 27 #xiaodeng #python之模块contextlib,为加强with语句而存在 #特别注意:python3和python2 ...