解决思路
贪心
public boolean validStackSequences(int[] pushed,int[] poped){
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()==poped[j]){
stack.pop();
j++;
}
}
return j == N;
}