剑指offer经典编程(十三)
来源:互联网 发布:手机计步器软件排行 编辑:程序博客网 时间:2024/05/01 04:09
栈的压入、弹出序列
输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长度是相等的)
import java.util.*;public class Solution { public boolean IsPopOrder(int [] pushA,int [] popA) { if(pushA.length==0||popA.length==0||popA.length!=pushA.length) return false; Stack stack = new Stack(); int len = pushA.length; int topIndex = 0; for (int i=0;i<len;i++){ stack.push(pushA[i]); while (topIndex<len && (Integer)stack.peek() == popA[topIndex]){ stack.pop(); topIndex++; } } return stack.empty()?true:false; }}
0 0
- 剑指offer经典编程(十三)
- 剑指offer之编程(十三)
- 剑指offer经典编程题(一)
- 剑指offer经典编程(二)
- 剑指offer经典编程(三)
- 剑指offer经典编程(四)
- 剑指offer经典编程(五)
- 剑指offer经典编程(六)
- 剑指offer经典编程(七)
- 剑指offer经典编程(八)
- 剑指offer经典编程(九)
- 剑指offer经典编程(十)
- 剑指offer经典编程(十一)
- 剑指offer经典编程(十二)
- 剑指offer经典编程(十四)
- 剑指offer经典编程(十五)
- 剑指offer经典编程(十六)
- 剑指offer经典编程(十七)
- Codeforces Gym 100962 J. Jimi Hendrix
- 游戏开发时关于UGUI的一些控件无法使用的问题
- 八皇后
- Spark Streaming使用Kafka保证数据零丢失
- 死锁的产生
- 剑指offer经典编程(十三)
- 两种常见的雷击浪涌和雷击浪涌防护电路设计概要
- 喇叭音量调节
- super的理解
- 解决unicodedecodeerror ascii codec can’t decode byte 0xd7 in position 9 ordinal not in range(128)
- 单词方阵
- VS2015+OPENCV3.1+WIN7配置
- Dijkstra算法+二维结构体数组
- hibernate悲观锁和乐观锁