题解 | #栈的压入、弹出序列#

栈的压入、弹出序列

http://www.nowcoder.com/practice/d77d11405cc7470d82554cb392585106

我不明白为什么我的就超时了?????

// function IsPopOrder(pushV, popV)
// {
//     // write code here
//     //看了题解的 辅助栈
//     let arr=[]
//     let start=0
//     for (let i=0;i<pushV.length;i++){
//        arr.push(pushV[i])
//        while(arr[arr.length-1]===popV[start]){
//            arr.pop()
//            start+=1
//        }
//     }
//     return start===popV.length-1
// }
// module.exports = {
//     IsPopOrder : IsPopOrder
// };
var inarr = []
var outarr = []
function IsPopOrder(pushV, popV)
{
    // write code here
    for (var i=0;i<pushV.length;i++) {
        inarr.push(pushV[i])
        while(inarr.length> 0 && inarr[inarr.length-1] === popV[0]) {
            inarr.pop()
            popV.shift()
        }
    }
    if(inarr.length>0) {
        return false
    } else {
        return true
    }
}
module.exports = {
    IsPopOrder : IsPopOrder
};
全部评论

相关推荐

不对是145个人…嗯…&nbsp;大家都没发现秋招提前批来了嘛..笑死我了
牛客39712426...:投了也是浪费时间,之前投米实习,除了浪费我时间写笔试题没有任何反馈,懒得投了
26届校招投递进展
点赞 评论 收藏
分享
想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务