给定一个二进制数组 nums , 计算其中最大连续 1 的个数。
我的代码哪里有错?为什么输入不了?C语言
```c
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> //最大连续1的个数
#include <stdlib.h>
int findMaxConsecutiveOnes(int* nums, int numsSize)
{
while (*nums==0||*nums==1)
{
int max = 0;
if (*nums == 1)
{
max++;
if (max > numsSize)
numsSize = max;
}
else max = 0;
nums++;
}
return numsSize;
}
int main()
{
int nums[10000000],i=0;
while (nums[i] == 0 || nums[i] == 1)
{
scanf("%d", &nums[i]);
i++;
}
int max = 0;
printf("%d", findMaxConsecutiveOnes( nums, max));
return 0;
}
下面这段代码为什么输出是1?错在哪里?
#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h> //最大连续1的个数
#include <stdlib.h>
int findMaxConsecutiveOnes(int* nums, int numsSize)
{
while (*nums==0||*nums==1)
{
int max = 0;
if (*nums == 1)
{
max++;
if (max > numsSize)
numsSize = max;
}
else max = 0;
nums++;
}
return numsSize;
}
int main()
{
int nums[]={1,1,1,0,1,1,1,1,1,0,0}, i = 0;
/*while (nums[i] == 0 || nums[i] == 1)
{
scanf("%d", &nums[i]);
i++;
}*/
int max = 0;
printf("%d", findMaxConsecutiveOnes( nums, max));
return 0;
}
```