import java.util.ArrayList;
import java.util.Stack;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
if(pushA.length == 1 && popA.length==1){
if(pushA[0] == popA[0]){
return true;
}else {
return false;
}
}
Stack<Integer> stack = new Stack<>();
ArrayList<Integer> list = new ArrayList<>();
for (int push : pushA){
list.add(push);
}
for(int pop : popA){
if(!stack.isEmpty() && pop == stack.peek()){
stack.pop();
continue;
}else if (!stack.isEmpty() && stack.contains(pop)){
return false;
}else {
int index = list.indexOf(pop);
for(int i=0;i<index;i++){
if((Integer) list.get(i)!=null){
stack.push((Integer) list.get(i));
list.set(i, null);
}
}
list.set(index,null);
}
}
if(stack.isEmpty()){
return true;
}
return false;
}
}