给定入栈序列,判断一个串是否为出栈序列
生活随笔
收集整理的這篇文章主要介紹了
给定入栈序列,判断一个串是否为出栈序列
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
劍指offer22:給定入棧序列,判斷一個串是否為出棧序列 public static boolean isOutStackSequence(int[] Spush, int[] Spop) {if (Spush.length <= 0 || Spop.length <= 0 || Spush.length != Spop.length)return false;int len = Spush.length;Stack<Integer> s = new Stack<Integer>();int i=0,j=0;for (; i < len; i++) {while(s.isEmpty()||Spop[i]!=s.peek()){if(j<len){s.push(Spush[j]);j++;}else{break;}}if(Spop[i]!=s.peek()) break;s.pop();}if(i<len)return false;else return true;}
?
轉載于:https://www.cnblogs.com/todayjust/p/5421585.html
總結
以上是生活随笔為你收集整理的给定入栈序列,判断一个串是否为出栈序列的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对java面试文章的技术漫谈的C#技术理
- 下一篇: iOS Storyboard创建APP