Why my program is memory limit exceeded??


  • 0
    J
    class MinStack {
    

    public:
    stack<int> s1;
    stack<int> s2;
    void push(int x) {
    s1.push(x);
    if(s2.size()==0||x<s2.top()){
    s2.push(x);
    }
    else{
    s2.push(s2.top());
    }
    }

    void pop() {
        s1.pop();
        s2.pop();
    }
    
    int top() {
        return s1.top();
    }
    
    int getMin() {
        return s2.top();
    }
    

    };
    my method is just the same as the answer,why i am wrong?


Log in to reply
 

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