【leetcode】155(Easy). Min Stack
解题思路:
没什么解题思路,烦死了这种题
提交代码:
class MinStack {
/** initialize your data structure here. */
Stack<Integer> st = new Stack<Integer>();
int min = Integer.MAX_VALUE;
public MinStack() {
}
public void push(int x) {
if (x <= min) {
st.push(min);
min = x;
}
st.push(x);
}
public void pop() {
if (st.pop() == min)
min = st.pop();
}
public int top() {
return st.peek();
}
public int getMin() {
return min;
}
}