题目:
https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
import java.util.ArrayDeque; import java.util.Deque; public class _150_EvalRPN { public int evalRPN(String[] tokens) { Deque<Integer> deque = new ArrayDeque<>(); for(int i=0;i<tokens.length;i++) { String token = tokens[i]; int r; int l; int ans; switch (token) { case "+": r = deque.poll(); l = deque.poll(); ans = l + r; break; case "-": r = deque.poll(); l = deque.poll(); ans = l - r; break; case "*": r = deque.poll(); l = deque.poll(); ans = l * r; break; case "/": r = deque.poll(); l = deque.poll(); ans = l / r; break; default: ans = Integer.valueOf(token); } deque.push(ans); } return deque.poll(); } }