栈的压入、弹出序列
public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA == null || popA==null || pushA.length==0 || pushA.length!=popA.length) { return false; } Stack<Integer> stack = new Stack<>(); for(int i=0, j=0; i<pushA.length;) { stack.push(pushA[i++]); while(j<popA.length && stack.peek()==popA[j]){ stack.pop(); j++; } } return stack.empty(); }
posted on 2019-02-28 18:57 www_practice 阅读(95) 评论(0) 收藏 举报
 
                     
                    
                 
                    
                 
 
         
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号