笨死
栈的压入、弹出序列
http://www.nowcoder.com/questionTerminal/d77d11405cc7470d82554cb392585106
思路:
1、第一个元素入栈
2、一致则出栈
3、不一致则继续入栈
import java.util.Stack; public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA==null&&popA==null) return true; Stack<Integer> stack = new Stack<>(); int i=0; int j=0; while(i<pushA.length){ stack.push(pushA[i]); while(!stack.isEmpty()&&stack.peek()==popA[j]){ //栈顶元素和当前popA一致就出栈 stack.pop(); j++; } //栈顶元素和当前popA不一致就继续入栈 i++; } return stack.isEmpty(); } }