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;
    }
};
相关推荐
Je1lyfish3 小时前
CMU15-445 (2025 Fall/2026 Spring) Project#3 - QueryExecution
linux·c语言·开发语言·数据结构·数据库·c++·算法
Brilliantwxx3 小时前
【C++】 vector(代码实现+坑点讲解)
开发语言·c++·笔记·算法
叼烟扛炮4 小时前
C++第三讲:类和对象(中)
开发语言·c++·类和对象
KuaCpp4 小时前
C++新特性学习
c++·学习
墨染千千秋4 小时前
C/C++ Keywords
c语言·c++
ximu_polaris4 小时前
设计模式(C++)-行为型模式-中介者模式
c++·设计模式·中介者模式
CSCN新手听安6 小时前
【Qt】Qt窗口(八)QFontDialog字体对话框,QInputDialog输入对话框的使用,小结
开发语言·c++·qt
tumu_C7 小时前
用std::function减缓C++模板代码膨胀和编译压力的一个场景
开发语言·c++
Hical617 小时前
C++17 实战心得:那些真正改变我写代码方式的特性
c++
Hical618 小时前
实测:C++20 协程 vs Go Gin vs Rust Actix,谁的 Web 性能更强?
c++