☰
【leetcode】Leetcode:485. Max Consecutive Ones
2026/10/23 1:02:14 网站建设 项目流程

问题描述:485. Max Consecutive Ones

Example 1:

Input: [1,1,0,1,1,1] Output: 3 Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.

Note:

The input array will only contain 0 and 1. The length of input array is a positive integer and will not exceed 10,000

难度等级:简单

这个题目很简单是遍历对应的向量,找到1连续最多的个数,返回对应的个数。

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

先从简单的刷起。。。O(∩_∩)O哈哈~

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询