My perfect accept, only 12 ms


  • 0
    Z
        int len = tokens.size();
        stack<int> tlist;
        for(int i = 0; i < len; i ++){
            int t = tokens[i][0] - '0';
            if((t >= 0 && t <= 9) || tokens[i].size() > 1){
                tlist.push(atoi(tokens[i].c_str()));
            }else{
                int b = tlist.top();
                tlist.pop();
                int a = tlist.top();
                tlist.pop();
                tlist.push(excute(tokens[i][0], a, b));
            }
        }
        
        return tlist.top();
    
    
    int excute(char e, int a, int b){
        if(e == '+'){
           return a + b; 
        }else if(e == '/'){
            return a / b;
        }else if(e == '-'){
            return a - b;
        }else if(e == '*'){
            return a * b;
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.