public boolean validateStackSequences(int[] pushed, int[] popped){
Stack<Integer> stack=new Stack<>();
int i=0;
for(int num:pushed){
stack.push(num);
while(!stack.isEmpty()&&stack.peek()==popped[i]){
stack.pop();
i++;
}
}
return stack.isEmpty();
}
剑指31 栈的压入、弹出序列
最新推荐文章于 2023-02-20 09:12:06 发布