剑指 Offer 30. 包含min函数的栈
class MinStack { Dequest = new ArrayDeque (), min = new ArrayDeque (); public MinStack() { } public void push(int x) { st.push(x); if(min.isEmpty()|| min.peek() >= x) { min.push(x); } } public void pop() { int x = st.pop(); if(x == min.peek()) { min.pop(); } } public int top() { return st.peek(); } public int min() { return min.peek(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)