[LeetCode]最大连续1的个数

2023-02-23,,

题目

代码

class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
int length=0;
int maxLength=0;
for(int i=0;i<nums.size();i++)
{
if(nums[i]==0)
length=0;
else
length++;
if(length>maxLength)
maxLength=length;
}
return maxLength;
}
};

[LeetCode]最大连续1的个数的相关教程结束。

《[LeetCode]最大连续1的个数.doc》

下载本文的Word格式文档,以方便收藏与打印。