import java.util.ArrayList;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
if(pushA.length == 0 && popA.length == 0){
return true;
}
if(pushA.length == 0 || popA.length == 0){
return false;
}
int[] temp = new int[pushA.length];
int pushIndex = 0;
int tempIndex = -1;
int popIndex = 0;
for(; popIndex < popA.length; ){
if(tempIndex >= 0 && temp[tempIndex] == popA[popIndex]){
// 模拟弹出操作
temp[tempIndex] = 1001;
tempIndex--;
popIndex++;
} else if(pushIndex < pushA.length) {
for(; pushIndex < pushA.length;){
// 模拟压入操作
tempIndex++;
temp[tempIndex] = pushA[pushIndex];
pushIndex++;
// 判断是否压入到目标值
if(temp[tempIndex] == popA[popIndex]){
break;
}
}
} else{
// 不匹配目标值,且无可以继续压入的数据
return false;
}
}
return temp[0] == 1001;
}
}