计算逆波兰式(后缀表达式)的值 运算符仅包含"+","-","*"和"",被操作数是整数 保证表达式合法,除法时向下取整。 数据范围:表达式的长度满足: 进阶:空间复杂度 , 时间复杂度 例如: ["20", "10", "+", "30", "*"] - ((20 + 10) * 30) - 900 ["40", "130", "50", "", "+"] - (40 + (130 50)) - 42
示例1
输入
["20","10","+","30","*"]
输出
900
示例2
输入
["20"]
输出
20
加载中...
import java.util.*; public class Solution { /** * * @param tokens string字符串一维数组 * @return int整型 */ public int evalRPN (String[] tokens) { // write code here } }
class Solution { public: /** * * @param tokens string字符串vector * @return int整型 */ int evalRPN(vector
& tokens) { // write code here } };
# # # @param tokens string字符串一维数组 # @return int整型 # class Solution: def evalRPN(self , tokens ): # write code here
/** * * @param tokens string字符串一维数组 * @return int整型 */ function evalRPN( tokens ) { // write code here } module.exports = { evalRPN : evalRPN };
# # # @param tokens string字符串一维数组 # @return int整型 # class Solution: def evalRPN(self , tokens ): # write code here
package main /** * * @param tokens string字符串一维数组 * @return int整型 */ func evalRPN( tokens []string ) int { // write code here }
["20","10","+","30","*"]
900
["20"]
20