https://leetcode-cn.com/problems/bao-han-minhan-shu-de-zhan-lcof
1234567891011121314151617181920212223
class MinStack { Stack<Integer> A, B; public MinStack() { A = new Stack<>(); B = new Stack<>(); } public void push(int x) { A.add(x); if(B.empty() || B.peek() >= x) B.add(x); } public void pop() { if(A.pop().equals(B.peek())) B.pop(); } public int top() { return A.peek(); } public int min() { return B.peek(); }}
fallenk
研究僧
Hangzhou, ZJU
Entradas
118
Categorias
19
Etiquetas
44
Update your browser to view this website correctly. Update my browser now
×