485_Max_Consecutive_Ones_Easy.c

来源:互联网 发布:织梦cms本地安装教程 编辑:程序博客网 时间:2024/06/08 17:06
/*Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.    The maximum number of consecutive 1s is 3.*/int findMaxConsecutiveOnes(int* nums, int numsSize) {    int i,count=0,max=0;    for(i=0;i<numsSize;i++)    {        if(nums[i]==1)            count++;        if(max <= count)            max = count;        if(nums[i]==0)            count=0;    }    return max;}
原创粉丝点击