Memory Limit out


  • 0
    J
    class MinStack {
    

    public:
    MinStack() :top_(-1){

    	/*stack.resize(n);*/ }
    void push(int x) {
    	top_++;
    	stack_.push_back(x);
    	if (top_ == 0)
    		min_ = 0;
    	else if (stack_[min_]>x)
    		min_ = top_;
    
    }
    
    void pop() {
    	if (top_ >= 0)
    	{
    		stack_.pop_back();
    
    		top_--;
    	}
    }
    
    int top() {
    	if (top_ >= 0)
    		return stack_[top_];
    }
    
    int getMin() {
    	return stack_[min_];
    }
    

    private:
    int top_;
    int min_;
    vector<int>stack_;
    int *stack;
    };


Log in to reply
 

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