https://leetcode.com/problems/max-consecutive-ones
分析
也就是找一个二进制数组中最大的连续1的个数,简单点就遍历统计就可以了。
int findMaxConsecutiveOnes(int* nums, int numsSize) {
int i = 0;
int maxLen = 0;
int tmpLen = 0;
for (i = 0; i < numsSize; i++)
{
if (nums[i] == 1)
{
tmpLen++;
if (tmpLen > maxLen)
{
maxLen = tmpLen;
}
}
else
{
tmpLen = 0;
}
}
return maxLen;
}