public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> stack = new Stack<Integer>();
int j = 0, n = pushed.length, m = popped.length;
for (int i = 0; i < n; ++i) {
stack.add(pushed[i]);
while (!stack.isEmpty() && j < m && stack.peek().equals(popped[j])) {
stack.pop();
j++;
}
}
return stack.isEmpty();
}
LeetCode-Algorithms-[Mid]面试题31. 栈的压入、弹出序列
猜你喜欢
转载自blog.csdn.net/m0_37302219/article/details/105574143
今日推荐
周排行