单调先生

关注

【leetcode】485. Max Consecutive Ones

单调先生

关注

阅读 33

2022-07-12

problem

​​485. Max Consecutive Ones​​

solution1:

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

 

 

参考

1. ​​Leetcode_485. Max Consecutive Ones​​;

完

相关推荐

素锦时年_1b00

485. Max Consecutive Ones

素锦时年_1b00 29 0 0

大漠雪关山月

【力扣算法 LeetCode】485. Max Consecutive Ones 最大连续 1 的个数

大漠雪关山月 85 0 0

独孤凌雪

LeetCode //C - 1004. Max Consecutive Ones III

独孤凌雪 9 0 0

color_小浣熊

【LeetCode】485. 最大连续1的个数

color_小浣熊 31 0 0

mafa1993

600. Non-negative Integers without Consecutive Ones

mafa1993 29 0 0

书坊尚

LeetCode 训练场:485. 最大连续1的个数

书坊尚 48 0 0

天行五煞

C++描述 LeetCode 485. 最大连续1的个数

天行五煞 45 0 0

书写经典

LeetCode 485. 最大连续 1 的个数(简单、数组)day18

书写经典 33 0 0

祈澈菇凉

【LeeCode】485. 最大连续 1 的个数

祈澈菇凉 113 0 0

mafa1993

LeetCode第一天(485.最大连续1的个数)

mafa1993 13 0 0

精彩评论(0)

0 0 举报