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

栈的压入、弹出序列

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
};
全部评论

相关推荐

码农索隆:这种hr,建议全中国推广
点赞 评论 收藏
分享
白火同学:能。我当初应届沟通了1200,收简历50,面试10左右吧,加油投吧
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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