Evaluate the value of an arithmetic expression in Reverse Polish Notation.
Valid operators are + , - , * , / . Each operand may be an integer or another expression.
Some examples:
["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -> 9 ["4", "13", "5", "/", "+"] -> (4 + (13 / 5)) -> 6<Solution>
直覺用 stack 來解,想法如下
- 如果是數字,就轉乘 int 放到 stack
- 如果是運算符號,就把最上面兩個數字拿出來做運算,結果再放到 stack
c++
kotlin
沒有留言:
張貼留言