import java.util.*;
public class Solution {
public boolean IsPopOrder(int [] pushA,int [] popA) {
Stack<Integer> stack = new Stack<>();
int j=0;
for(int i=0;i<pushA.length;++i){
stack.push(pushA[i]);
while(!stack.isEmpty()&&stack.peek()==popA[j]){
++j;
stack.pop();
}
}
return stack.isEmpty();
}
}
2021-12-14(JZ31 栈的压入、弹出序列)
最新推荐文章于 2024-06-14 14:22:02 发布