1.题目:
给定一个二进制数组, 计算其中最大连续1的个数。
Given a binary array, find the maximum number of consecutive 1s in this array.
2.代码:
int findMaxConsecutiveOnes(int* nums, int numsSize) {
int n=0,max=0;
for(int i=0;i<numsSize;i++){
if(nums[i]==1){
n++;
if(i==numsSize-1){ //解决[1]这种问题
if(max<=n)
max=n;
}
}
else{
if(max<=n)
max=n;
n=0;
}
}
return max;
}
3.知识点:
NULL