计算逆波兰式(后缀表达式)的值
运算符仅包含"+","-","*"和"/",被操作数可能是整数或其他表达式
例如:
就是简单的栈应用
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;
}
if(tokens


京公网安备 11010502036488号