返回题库

逆波兰表达式求值

Evaluate Reverse Polish Notation

专题
Algorithmic Programming / 算法编程
难度
L3
来源
Citadel

题目详情

问题:逆波兰表达式求值

考察:数组、数学、栈

来源:DSA Prep / Citadel

链接:https://leetcode.com/problems/evaluate-reverse-polish-notation

Problem: Evaluate Reverse Polish Notation

Patterns: Array, Math, Stack

Recency: 2yr

Link: https://leetcode.com/problems/evaluate-reverse-polish-notation

Source: https://www.dsaprep.dev/blog/citadel-coding-interview-questions/

解析

思路:用栈保存操作数。遇到数字入栈,遇到运算符弹出两个数按顺序计算并把结果压回;注意减法和除法的左右操作数顺序。

复杂度:时间 O(n),空间 O(n)。