题解 | #栈的压入、弹出序列#
栈的压入、弹出序列
https://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106
import java.util.LinkedList; public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { LinkedList<Integer> stack = new LinkedList<Integer>(); for(int pushIdx = 0, popIdx = 0; pushIdx < pushA.length; pushIdx++) { stack.addLast(pushA[pushIdx]); while((stack.size() > 0) && (popIdx < popA.length) && (stack.getLast() == popA[popIdx])) { popIdx++; stack.removeLast(); } } return stack.size() == 0; } }