class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
Deque<Integer> stack = new ArrayDeque();
int j = 0;// j当作popped的指针,判断当前是否是弹出的数值
for(int push : pushed){
stack.push(push);
// peek()是取出来并不删除,pop()是取出然后删除
while(j < popped.length && !stack.isEmpty() && stack.peek() == popped[j]){
stack.pop();
j++;
}
}
return j == popped.length;
}
}