2022.04.02(LC_150_逆波兰表达式求值)
方法:模拟
class Solution {
public int evalRPN(String[] tokens) {
Deque
for (String token : tokens) {
if ("+".equals(token)) {
int num2 = stack.pop();
int num1 = stack.pop();
stack.push(num1 + num2);
} else if ("-".equals(token)) {
int num2 = stack.pop();
int num1 = stack.pop();
stack.push(num1 - num2)
共有 0 条评论