public static boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stack = new Stack<>();
int i = 0;
for (int item : pushed) {
stack.add(item);
while (!stack.empty() && stack.peek() == popped[i]) {
stack.pop();
i++;
}
}
return stack.isEmpty();
}
栈的压入、弹出序列
最新推荐文章于 2021-03-27 10:53:49 发布