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

栈的压入、弹出序列

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

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务