解:
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