题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
import java.util.ArrayList;
import java.util.Arrays;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
//模拟入栈出栈
int curPush = 0;
int curPop = 0;
for(int i = 0; i < pushA.length; i++){
pushA[curPush] = pushA[i];
while(curPush>=0 && pushA[curPush] == popA[curPop]){
curPop++;
curPush--;
}
curPush++;
}
return curPush == 0;
}
}
