← 返回 bloomberg 的题目列表Evaluate Reverse Polish Notation Variation
类型:online_judge
Given a variation of Reverse Polish Notation (RPN) expression, calculate its result. The variation may include additional operators or modify the input format. Input is provided as a list where each element is an operand (integer) or operator. Consider the characteristic of variations and provide the corresponding input format. Implement a function evaluate_rpn(expression: List[str]) -> int to compute the result.
Test cases:
Input: ["2", "1", "+", "3", "*"]
Output: 9
Input: ["4", "13", "5", "/", "+"]
Output: 6
Input: ["10", "6", "9", "3", "+", "-11", "*", "/", "*", "17", "+", "5", "+"]
Output: 22
Hints:
Operators only include +, -, *, /.
Each operand (which may not be integer) is a string, representing a non-negative integer less than 10 or a single operator.
Integer division keeps only the quotient portion. Other operations follow conventional mathematical computation.
Example
Input
"2 1 + 3 *"