题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
import java.util.*;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
Stack<integer> stack = new Stack<>();
stack.push(pushA[0]);
int i=0;
int j=0;
while(i<pushA.length&&j<popA.length){
while(popA[j]!=stack.peek()){
i++;
if(i==pushA.length){
return false;
}
stack.push(pushA[i]);
}
stack.pop();
if(stack.isEmpty()){
i++;
if(i==pushA.length){
return true;
}
stack.push(pushA[i]);
}</integer>
j++; } return true; }
}