Unverified Commit c78f6ad6 authored by 程序员吴师兄's avatar 程序员吴师兄 Committed by GitHub
Browse files

Merge pull request #57 from zjming/master

0155-0215-0290-0394-0946
parents 846a6907 b6bdf8cc
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