LeetCode OJ 150. Evaluate Reverse Polish Notation
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 ...
- 150. Evaluate Reverse Polish Notation - LeetCode
Question 150. Evaluate Reverse Polish Notation Solution 2 1 + 3 * 是((2+1)*3)的后缀(postfix)或逆波兰(reverse ...
- 【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 +, -, ...
随机推荐
- 2016HUAS_ACM暑假集训2G - Who's in the Middle
这个题真的没什么好说的.一个排序就能解决的问题.唯一感到不爽的是这道题不是0msAC的,希望各位大神能够给我点指导. 头文件#include<algorithm>,注意一下排序函数的用法就 ...
- 支持向量机(SVM)基础
版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...
- world machine, 输出lightmap
一,输出黑白lightmap: 二,输出彩色lightmap: 需要注意的是:当输出黑白lightmap时,输出设备要用Height Output:当输出彩色lightmap时,输出设备要用Bitma ...
- NSMutableAttributedString 富文本删除线的用法
#import <UIKit/UIKit.h> //价格 NSString *priceStr = @"99元 剁手价66元"; NSMutableAttributed ...
- js计算日期之间的月份差
<script type="text/javascript"> getMonthBetween("2015-05-01","2016-05 ...
- 学习SQL的点点滴滴(三)-修改数据库的兼容级别
语法 ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = { 80 | 90 | 100 } 参数 database_name 要修改的数据库 ...
- linux下生成rsa密钥的方法
首先生成密钥,用命令ssh-keygen –t rsa 运行后可以一直空格,生成密钥,id_rsa和id_rsa.pub文件 ,默认放在/root/.ssh/下,.ssh文件是隐藏的,要显示隐藏文件才 ...
- springboot教程
http://www.cnblogs.com/java-zhao/tag/spring-boot/ http://blog.csdn.net/liaokailin/article/category/5 ...
- 初识UML
最近的学习中,遇到几次UML图,很是迷糊,确切的说,看不太懂.查阅UML相关资料,基本解决了这个问题.UML看起来还是相当深奥,这里只提一下解决问题的部分知识.(以下知识来自网络) Unified M ...
- 第一波实习的前端笔记(2)——js.md
1.如何解决移动端点透问题? $('xx').on('touchend', function(event){ event.preventDefault(); }) 但是,存在滑动页面会触发问题.期待更 ...