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

栈的压入、弹出序列

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

function IsPopOrder(pushV, popV)
{
    // write code here
    let helparr = [];
    let ind = 0;
    for(let i of pushV) {
      helparr.push(i);
      while(helparr.length > 0) {
        if(helparr[helparr.length - 1] == popV[ind]){
          helparr.pop();
          ind = ind + 1;
        }else{
          break;
        }
      }
    }
    return helparr.length  == 0;
}
module.exports = {
    IsPopOrder : IsPopOrder
};

算法题合集 文章被收录于专栏

自己做算法的解题代码

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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