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;
    }
};
相关推荐
史迪仔011226 分钟前
[QML] QML IMage图像处理
开发语言·前端·javascript·c++·qt
会编程的土豆2 小时前
【数据结构与算法】再次全面了解LCS底层
开发语言·数据结构·c++·算法
低频电磁之道2 小时前
解决 Windows C++ DLL 导出类不可见的编译错误
c++·windows
君义_noip3 小时前
信息学奥赛一本通 4150:【GESP2509七级】⾦币收集 | 洛谷 P14078 [GESP202509 七级] 金币收集
c++·算法·gesp·信息学奥赛·csp-s
Ricky_Theseus3 小时前
静态链接与动态链接
c++
摸个小yu3 小时前
【力扣LeetCode热题h100】链表、二叉树
算法·leetcode·链表
澈2074 小时前
双指针,数组去重
c++·算法
小辉同志4 小时前
207. 课程表
c++·算法·力扣·图论
feng_you_ying_li5 小时前
C++11,{}的初始化情况与左右值及其引用
开发语言·数据结构·c++
skywalker_115 小时前
力扣hot100-5(盛最多水的容器),6(三数之和)
算法·leetcode·职场和发展