class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
if(null == pushed || null == popped)
return false;
Stack<Integer> stack = new Stack<>();
int pos = 0;
for(int i : pushed) {
stack.push(i);
while(!stack.isEmpty() && popped[pos] == stack.peek()) {
stack.pop();
pos++;
}
}
return stack.isEmpty();
}
}
LeetCode 946验证栈序列(java)
最新推荐文章于 2020-12-02 14:25:37 发布
