150. Evaluate Reverse Polish Notation Medium
1/**
2 * [150] Evaluate Reverse Polish Notation
3 *
4 * Evaluate the value of an arithmetic expression in <a href="http://en.wikipedia.org/wiki/Reverse_Polish_notation" target="_blank">Reverse Polish Notation</a>.
5 * Valid operators are +, -, *, and /. Each operand may be an integer or another expression.
6 * Note that division between two integers should truncate toward zero.
7 * It is guaranteed that the given RPN expression is always valid. That means the expression would always evaluate to a result, and there will not be any division by zero operation.
8 *
9 * Example 1:
10 *
11 * Input: tokens = ["2","1","+","3","*"]
12 * Output: 9
13 * Explanation: ((2 + 1) * 3) = 9
14 *
15 * Example 2:
16 *
17 * Input: tokens = ["4","13","5","/","+"]
18 * Output: 6
19 * Explanation: (4 + (13 / 5)) = 6
20 *
21 * Example 3:
22 *
23 * Input: tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"]
24 * Output: 22
25 * Explanation: ((10 * (6 / ((9 + 3) * -11))) + 17) + 5
26 * = ((10 * (6 / (12 * -11))) + 17) + 5
27 * = ((10 * (6 / -132)) + 17) + 5
28 * = ((10 * 0) + 17) + 5
29 * = (0 + 17) + 5
30 * = 17 + 5
31 * = 22
32 *
33 *
34 * Constraints:
35 *
36 * 1 <= tokens.length <= 10^4
37 * tokens[i] is either an operator: "+", "-", "*", or "/", or an integer in the range [-200, 200].
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/evaluate-reverse-polish-notation/
43// discuss: https://leetcode.com/problems/evaluate-reverse-polish-notation/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn eval_rpn(tokens: Vec<String>) -> i32 {
49 0
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_150() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.