题目

题解

import java.util.Stack;

public class Solution {

    Stack<Integer> stack = new Stack();
    Stack<Integer> helpStack = new Stack();
    public void push(int node) {
        int helpStackTop = node;
        if (!helpStack.isEmpty()) {
            helpStackTop = Math.min(helpStack.peek(), helpStackTop);
        }
        stack.push(node);
        helpStack.push(helpStackTop);
    }
    
    public void pop() {
        if (stack.isEmpty()) {
            return;
        }
        stack.pop();
        helpStack.pop();
    }
    
    public int top() {
        return stack.peek();
    }
    
    public int min() {
        return helpStack.peek();
    }
}

Leetcode名企之路


Acceml
284 声望79 粉丝

码蹄疾,毕业于哈尔滨工业大学。