import java.util.ArrayList; import java.util.Stack; public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { Stack<Integer> s=new Stack<>(); int j=0; for(int i=0;i<pushA.length;i++) { s.push(pushA[i]);//先压入栈 while(!s.empty()&&s.peek()==popA[j])//栈顶元素和popA某数组元素相同,就出栈 { s.pop(); j++; } } return s.isEmpty();//为空说明出栈元素正确 } }