用栈解决的相关问题
1.已知某个栈的压栈序列,判断某个序列是不是该压栈序列的弹出序列。
public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA.length==0) return false; Stack<Integer> stack=new Stack<Integer>(); for(int i=0,j=0;i<pushA.length;i++){ stack.push(pushA[i]); while(j<popA.length&&stack.peek()==popA[j]){ stack.pop(); j++; } } return stack.isEmpty(); }
本文来自博客园,作者:LeeJuly,转载请注明原文链接:https://www.cnblogs.com/peterleee/p/10712940.html

浙公网安备 33010602011771号