Memory limit exceeded? What's wrong with my codes?


  • 0
    Q

    class MinStack {

    public:

    stack<int> s_min;
    stack<int> s_data;
    
    void push(int x) {
        s_data.push(x);
        if(s_min.empty())
        {
            s_min.push(x);
        }
        else if(x<s_min.top())
        {
            s_min.push(x);
        }
        else
        {
            s_min.push(s_min.top());
        }
        
    }
    
    void pop() {
        s_data.pop();
        s_min.pop();
        
    }
    
    int top() {
        return s_data.top();
    }
    
    int getMin() {
        return s_min.top();
    }
    

    };


  • 0
    S

    mine also giving the same...


Log in to reply
 

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