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;
}