图片说明

/**
  * 
  * @param tokens string字符串一维数组 
  * @return int整型
  */
function evalRPN( tokens ) {
    // write code here
    let stack = []
    for(let x of tokens){
        if(x === '+'){
            let num1 = stack.pop();
            let num2 = stack.pop();
            stack.push(num1+num2)
        }else if(x === '-'){
            let num1 = stack.pop();
            let num2 = stack.pop();
            stack.push(num2-num1);
        }else if(x === '*'){
            let num1 = stack.pop();
            let num2 = stack.pop();
            stack.push(num1*num2)
        }else if(x === '/'){
            let num1 = stack.pop();
            let num2 = stack.pop();
            let num = num2/num1
            stack.push(parseInt(num))
        }else{
            stack.push(parseInt(x))
        }
    }
    return stack[0]
}
module.exports = {
    evalRPN : evalRPN
};