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 +, -, ...
随机推荐
- java设计6大设计原则
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- knockout 学习实例5 style
<!DOCTYPE html><html><head> <meta charset="utf-8"> <title>&l ...
- CenOS 7 安装mysql
1:安装YUM源 2:利用file zilla 将mysql文件拖放到 /var/opt 目录下 3:在centos当中,已经将mysql的文件放到了 /var/opt 我们只需要安装就可以 安装 ...
- node版本管理器nvm(服务器项目相关)
git项目 https://github.com/creationix/nvm 1.下载并安装NVM脚本 curl https://raw.githubusercontent.com/creation ...
- Xcode解决代码高亮、语法提示、错误警告等功能失效的解决方法
在编写xcode的项目的时候出现过代码不高亮的症状,而且所有的warning都不再提示,include的内容也显示symbol not found,非常奇怪,解决方案如下: 方法一: 1.把.pch里 ...
- 【MySQL】探究之常用SQL
一些SQL命令(不断更新,我总记不住,哭) List 建库建表 表的重命名(不区分大小写) 列的重命名 编码 修改结构 添加删除索引 大批量删除 binlog相关 select相关 数据库备份和恢复 ...
- 用友的凭证update
select pk_glorgbook from bd_glorgbook where glorgbookcode='0100-0001';--0001N510000000006K4X ' and p ...
- js传递参数中包含+号时的处理方法
encodeURI(url).replace(/\+/g, '%2B') 例子: $scope.getAnesthesiawaystatistical = function (annual, anes ...
- Mobile Web调试工具Weinre (reproduce)
Mobile Web调试工具Weinre 现在.将来,用移动设备上网越来越成为主流.但对于开发者们来说,移动web的调试一直是个难题,前期可以使用模拟器来协助调试,但到了真机调试阶段就让人非常头痛.而 ...
- javascript内建对象
内建对象等价于内建构造器内建对象大致分为三类:数据封装类对象--Object.Array.Boolean.Number和String工具类对象--Math.Date.RegExp等用于提供遍历的对象错 ...