1. 常规思路
public boolean IsPopOrder(int[] pushA, int[] popA)
{
int nLength = pushA.length;
Stack<Integer> s = new Stack<>();
int i = 0, j = 0;
// 先对序列的情况进行判断
if (pushA == null || popA == null
|| nLength <= 0 || pushA.length != popA.length)
{
return false;
}
for (i=0; i<nLength; i++)
{
s.push(pushA[i]);
// 这里用while
while (!s.empty() && s.peek() == popA[j])
{
s.pop();
j++; // 出栈元素加1
}
}
return s.empty()? true:false;
}