溪语
Less Is More

解:

Input: [1,1,0,1,1,1]
Output: 3
Explanation: The first two digits or the last three digits are consecutive 1s.
    The maximum number of consecutive 1s is 3.

求出数组中连续1的最大的个数

let count = 0; // 记录连续+1的值
    let max = 0;// 记录最大的值
    for(let i = 0; i < nums.length; i++){
        if(nums[i] == 1)  count++;
        if(max < count)   max=count;
        if(nums[i] == 0)   count=0;
    }
    return max

  

posted on 2018-07-06 14:32  溪语_8023  阅读(100)  评论(0编辑  收藏  举报