计算逆波兰式(后缀表达式)的值
运算符仅包含"+","-","*"和"/",被操作数是整数
保证表达式合法,除法时向下取整。
数据范围:表达式的长度满足: 
进阶:空间复杂度
, 时间复杂度 )
进阶:空间复杂度
例如:
["20", "10", "+", "30", "*"] -> ((20 + 10) * 30) -> 900 ["40", "130", "50", "/", "+"] -> (40 + (130 / 50)) -> 42
["20", "10", "+", "30", "*"] -> ((20 + 10) * 30) -> 900 ["40", "130", "50", "/", "+"] -> (40 + (130 / 50)) -> 42
["20","10","+","30","*"]
900
["20"]
20
function evalRPN(tokens) { // write code here const stack = []; for (let i = 0; i < tokens.length; i++) { const d = tokens[i]; if (isNaN(d)) { let n2 = stack.pop(); let n1 = stack.pop(); switch (d) { case '+': stack.push(n1 + n2) break; case '-': stack.push(n1 - n2) break; case '*': stack.push(n1 * n2) break; case '/': stack.push(Math.floor(n1 / n2)) break; default: break; } } else { stack.push(parseInt(d)); } } return stack.pop() }