Commit 5bf978cf authored by JingmingZhang's avatar JingmingZhang
Browse files

Solved @zjming

parents
class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
int N = pushed.length;
Stack<Integer> stack = new Stack();
int j = 0;
for (int x: pushed) {
stack.push(x);
while (!stack.isEmpty() && j < N && stack.peek() == popped[j]) {
//队头元素出队,栈顶元素出栈
stack.pop();
j++;
}
}
if (!stack.isEmpty()){
return false;
}
return true;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment