剑指offer22 栈的压入、弹出序列
2017-07-26 11:18
134 查看
写的一个代码,虽然正确通过了,但我觉得会报vector越界的错误
class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { int length1 = pushV.size(); int length2 = popV.size(); if(length1 <= 0 || length2 <= 0 || length1 != length2) return false; stack<int> sta; int current = 0; for(int i = 0;i < length2;i++){ if(sta.empty()){ while(pushV[current] != popV[i]){ if(current >= length1) return false; sta.push(pushV[current]); current++; } current++; } else{ if(sta.top() == popV[i]){ sta.pop(); } else{ while(pushV[current] != popV[i]){ if(current >= length1) return false; sta.push(pushV[current]); current++; } current++; } } } return true; } };
相关文章推荐
- 【剑指Offer】面试题22:栈的压入,弹出序列
- 剑指offer面试题22 栈的压入、弹出序列
- 【剑指offer】面试题22:栈的压入、弹出序列
- 【面试题】剑指Offer-22-栈的压入和弹出序列
- 剑指offer 22 栈的压入、弹出序列
- 【剑指Offer学习】【面试题22:栈的压入、弹出序列】
- 【剑指offer】题22:栈的压入、弹出序列
- 剑指offer 面试题22 栈的压入弹出序列
- 剑指Offer22:栈的压入、弹出序列
- 剑指offer之面试题22:栈的压入、弹出序列
- 剑指Offer面试题22(Java版):栈的压入、弹出序列
- 剑指offer面试题 22 栈的压入、弹出序列的匹配
- 剑指Offer_面试题22_栈的压入弹出序列
- 剑指offer面试题22:栈的压入、弹出序列
- 剑指offer 面试题22 栈的压入、弹出序列
- 剑指offer之面试题22:栈的压入、弹出序列
- 剑指offer 22 栈的压入、弹出序列
- 剑指offer——面试题22:栈的压入、弹出序列
- 剑指Offer-面试题22:栈的压入、弹出序列
- 剑指offer-4-面试题22:栈的压入、弹出序列