栈的压入,弹出序列

理解题意:

            popV  

5            

4  

3  

2  

1          1

pushV

最差情况是popv前面的所有元素都不一样,只有最后一个元素是pushv的第一个元素。

pushv中正序连续元素正好是pop对应位置反序元素。

 1 class Solution {
 2 public:
 3     bool IsPopOrder(vector<int> pushV,vector<int> popV) {
 4         int length = pushV.size()-1;
 5         int i=length;
 6         int j=0;
 7         int count=0;
 8         while(j<=length && i>=0){
 9             if(pushV[i]==popV[j]) count++;
10             else count=0;
11             i--;
12             j++;
13         }
14         if(count>=1) return true;
15         return false;
16     }
17 };

 

posted @ 2019-07-08 15:23  Austin_anheqiao  阅读(120)  评论(0编辑  收藏  举报