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

栈的压入、弹出序列

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

使用一个栈模拟压入弹出操作

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

相关推荐

用微笑面对困难:你出于礼貌叫了人一声大姐,大姐很欣慰,她真把你当老弟
点赞 评论 收藏
分享
评论
7
收藏
分享

创作者周榜

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