Sakura

sakura

博客园 首页 新随笔 联系 订阅 管理

 

 

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();
    }
}

 

posted on 2020-07-15 20:47  .geek  阅读(103)  评论(0编辑  收藏  举报