栈的压入弹出序列

题目

https://leetcode-cn.com/problems/zhan-de-ya-ru-dan-chu-xu-lie-lcof

解法

1
2
3
4
5
6
7
8
9
10
11
12
public boolean validateStackSequences(int[] pushed, int[] poped) {
Stack<Integer> stack = new Stack<>();
int i = 0;
for (int num : pushed) {
stack.push(num);
while (!stack.isEmpty() && stack.peek() == poped[i]) {
stack.pop();
i++;
}
}
return stack.isEmpty();
}
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×