思路
栈的压入、弹出序列
http://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106
//代码
import java.util.ArrayList; import java.util.Stack; public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { Stack<Integer> stack = new Stack<Integer>(); //stack.push(pushA[0]); boolean r = true; int i = 0; for(int popNum:popA){ for(i=i; i<pushA.length; i++){ int pushNum = pushA[i]; boolean TF = false; for(Integer s:stack){ if(popNum==s){ TF = true; break; } } if( TF==false ){ stack.push(pushNum); //continue; }else{ int ss = stack.pop(); if(ss!=popNum){ r = false; } break; } //最后一个的元素 if(i == pushA.length-1){ int ss = stack.pop(); if(ss!=popNum){ r = false; } break; } } if(r==false){ break; } } return r; } }