import java.util.*;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
Stack<Integer> stack = new Stack<>();
int i,j = 0;
for(i = 0;i< pushA.length;i++){
stack.push(pushA[i]);
while(j < popA.length && !stack.isEmpty() && stack.peek() == popA[j]){
stack.pop();
j++;
}
}
return stack.isEmpty();
}
}

京公网安备 11010502036488号