C++ | Leetcode C++题解之第485题最大连续1的个数

题目:

题解:

cpp 复制代码
class Solution {
public:
    int findMaxConsecutiveOnes(vector<int>& nums) {
        int maxCount = 0, count = 0;
        int n = nums.size();
        for (int i = 0; i < n; i++) {
            if (nums[i] == 1) {
                count++;
            } else {
                maxCount = max(maxCount, count);
                count = 0;
            }
        }
        maxCount = max(maxCount, count);
        return maxCount;
    }
};
相关推荐
hehelm6 分钟前
IO 多路复用 — Reactor
linux·服务器·网络·数据库·c++
灵晔君1 小时前
【C++】二叉搜索树
开发语言·c++
鱼子星_1 小时前
【C++】内存管理:内存分布,new/delete的使用及细节处理,new/delete的底层,定位new表达式
开发语言·c++·笔记
鱼子星_2 小时前
【C++】string(上):string的基本使用
c++·笔记·字符串
tachibana23 小时前
hot100 课程表(207)
java·数据结构·算法·leetcode
神仙别闹3 小时前
编写基于C++ Huffman 算法的无损压缩程序和解压程序
java·c++·算法
炸膛坦客3 小时前
单片机/C/C++八股:(二十三)#define 和 typedef 的区别
c语言·c++·单片机
旖-旎3 小时前
《LeetCode 646 最长数对链 || LeetCode 1143 最长公共子序列》
c++·算法·leetcode·动态规划
Frostnova丶3 小时前
(15)LeetCode 189. 轮转数组
数据结构·算法·leetcode
阿米亚波4 小时前
【C++ STL】std::list
c++·windows·笔记·stl·list