剑指offer 22 栈的压入、弹出序列
2016-05-23 09:53
211 查看
class Solution { public: bool IsPopOrder(vector<int> pushV,vector<int> popV) { bool result=false; int n1=pushV.size(); int n2=popV.size(); if(!n1||!n2) return result; int push_index=0; int pop_index=0; stack<int> s; s.push(pushV[push_index++]); while(pop_index<n2) { while(s.top()!=popV[pop_index]&&push_index<n1) s.push(pushV[push_index++]); if(s.top()==popV[pop_index]) { s.pop(); pop_index++; } else break; } if(pop_index==n2) result=true; return result; } };
*不可以在堆栈为空时,使用s.top()函数,会发生未知!
*要注意边界条件!!
相关文章推荐
- html固定宽度下拉框内容显示不全问题解决方法
- ReactiveCocoa之简介(一)
- ajax跨域jsonp详解
- 前端常用规范
- 在IE8上JS实现combobox支持拼音检索功能
- confrim() 方法 的简单介绍应用
- 开始学习javascript(什么是DHTML)
- js 正则表达式 判断车牌号
- Jquery引入src js 使用Chart.js
- [Effective JavaScript 笔记] 第14条:当心命名函数表达式笨拙的作用域
- ajax 提交数组
- vsftp日志xferlog格式分析
- AngularJS进阶(三十八)上拉加载问题解决方法
- AngularJS进阶(三十八)上拉加载问题解决方法
- caffe安装吐血总结
- CSS学习目录
- 浅析JavaScript 箭头函数 generator Date JSON
- javascript-表格移动光标变色
- Could not find the Visual SourceSafe Internet Web Service connection information for the specified database Would you like to launch the Visual sourceSafe connection wizard?
- HTMl5的sessionStorage和localStorage