946. Validate Stack Sequences 发表于 2022-05-05 12345678910111213141516class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { int index = 0; Stack<Integer> stack = new Stack<>(); for (int num : pushed) { stack.push(num); while (!stack.isEmpty() && popped[index] == stack.peek()) { stack.pop(); index++; } } return stack.isEmpty(); }} Reference946. Validate Stack Sequences剑指 Offer 31. 栈的压入、弹出序列