数组 1/3
力扣283----最大连续1的个数
比较基础的一道题,要注意不要忘记统计最大连续1的个数。
class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
//maxcount 最大连续1的个数 count 当前连续1的个数
int maxcount = 0; int count = 0;
for(int i = 0; i < nums.size(); i++) {
if(nums[i] == 1) {
count ++;
} else {
//容易忘记统计最大连续1个数
maxcount = max(maxcount,count);
count = 0;
}
}
maxcount = max(maxcount,count);
return maxcount;
}
};