美文网首页
#485 Max Consecutive Ones

#485 Max Consecutive Ones

作者: 乐正君Krizma | 来源:发表于2017-04-28 16:07 被阅读0次

    题目:

    Given a binary array, find the maximum number of consecutive 1s in this array.



    代码:

    var findMaxConsecutiveOnes = function(nums) {    

    let ans = 0, tmp = 0, len = nums.length;   

    nums[len] = 0;   

     for(let i=0;i<len+1;++i){

    if (tmp != tmp+nums[i]) {

    tmp += nums[i];

    } else {

    ans = (ans>tmp)?ans:tmp;

    tmp = 0;

    }

    }

    return ans;

    };

    相关文章

      网友评论

          本文标题:#485 Max Consecutive Ones

          本文链接:https://www.haomeiwen.com/subject/ybfazttx.html