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

function IsPopOrder(pushV, popV)
{
    // write code here
    //模拟整个压栈和出栈过程就可以了
    //创建一个栈用于模拟
    let stack = []
    let j = 0
    for (let i = 0; i < pushV.length; i++){
        stack.push(pushV[i])
        while(stack.length !== 0 && stack[stack.length - 1] == popV[j]){
             j++
             stack.pop()
        }
        
    }
    if(stack.length == 0) {
        return true
    }else {
        return false
    }
    
}
module.exports = {
    IsPopOrder : IsPopOrder
};
全部评论

相关推荐

09-27 14:42
已编辑
浙江大学 Java
未来未临:把浙大放大加粗就行
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务