class Solution {
public boolean validateStackSequences(int[] pushed, int[] popped) {
Stack<Integer> s = new Stack<>();
int k=0;
for(int i=0;i<pushed.length;i++){
s.push(pushed[i]);
while((!s.isEmpty())&&s.peek()==popped[k]){
s.pop();
k++;
}
}
return s.isEmpty();
}
}
使用栈进行压入弹出进行判断