public int[] getMinStack (int[][] op) { // write code here Stack<Integer> stack1 = new Stack<>(); Stack<Integer> stack2 = new Stack<>(); List<Integer> list = new ArrayList<>(); for(int i=0;i<op.length;i++){ if(op[i][0]==3){ list.add(stack2.peek()); }else if(op[i][0]==2){ int a = stack1.pop(); if(a==stack2.peek()) stack2.pop(); }else{ int temp = op[i][1]; stack1.push(temp); //这里注意判断stack2是否为空 if(stack2.isEmpty() || temp<=stack2.peek()) stack2.push(temp); } } int[] res = new int[list.size()]; for(int i=0;i<list.size();i++){ res[i] = list.get(i); } return res; }