包含min函数的栈
![](https://img2023.cnblogs.com/blog/608798/202211/608798-20221127110251078-975459225.png)
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
public class Solution {
Stack<Integer> stack = new Stack<Integer>();
public void push(int node) {
stack.push(node);
}
public void pop() {
stack.pop();
}
public int top() {
int top = stack.pop();
stack.push(top);
return top;
}
public int min() {
List<Integer> list= new ArrayList<Integer>();
while(!stack.isEmpty()){
list.add(stack.pop());
}
for(int i=list.size()-1; i>=0; i--){
stack.push(list.get(i));
}
list.sort(new Comparator<Integer>(){
public int compare(Integer A, Integer B){
return A-B;
}
});
return list.get(0);
}
}