LeetCode 485. 最大连续1的个数

题目链接:https://leetcode-cn.com/problems/max-consecutive-ones/

给定一个二进制数组, 计算其中最大连续1的个数。

示例 1:

输入: [1,1,0,1,1,1]
输出: 3
解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 3.
注意:

输入的数组只包含 0 和1。
输入数组的长度是正整数,且不超过 10,000。

 1 int findMaxConsecutiveOnes(int* nums, int numsSize){
 2     int sum=0;
 3     int maxs=0;
 4     for(int i=0;i<numsSize;i++){
 5         if(nums[i]==1){
 6             sum++;
 7             if(sum>maxs) maxs=sum;
 8         }else{
 9             sum=0;
10         }
11     }
12     return maxs;
13 }
原文地址:https://www.cnblogs.com/wydxry/p/11340808.html