#栈#单调栈#leetCode94.验证栈序列

class Solution {
    public boolean validateStackSequences(int[] pushed, int[] popped) {
        Deque<Integer> q = new LinkedList<>();
        int N = pushed.length;
        int j = 0;
        for(int x:pushed) {
            q.push(x);
            while(q.isEmpty()==false && q.peek()==popped[j]) {
                q.pop();
                ++j;
            }
        }
        return q.isEmpty();
    }
}
原文地址:https://www.cnblogs.com/lyr-2000/p/13307874.html