leetcode-栈练习-evaluate-reverse-polish-notation
evaluate-reverse-polish-notation
https://www.nowcoder.com/practice/22f9d7dd89374b6c8289e44237c70447?tpId=46&tqId=29031&tPage=1&rp=1&ru=/ta/leetcode&qru=/ta/leetcode/question-ranking
计算逆波兰式(后缀表达式)的值
运算符仅包含"+","-","*"和"/",被操作数可能是整数或其他表达式
例如:
就是简单的栈应用
import java.util.Stack; public class Solution { public int evalRPN(String[] tokens) { Stack<Integer> stack = new Stack<>(); for(int i=0; i < tokens.length; i++){ if(tokens[i].equals("+")){ int op1 = stack.pop(); int op2 = stack.pop(); stack.push(op1+op2); continue; } i
剩余60%内容,订阅专栏后可继续查看/也可单篇购买
小白刷Leetcode 文章被收录于专栏
那些必刷的leetcode