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;
    }
};
相关推荐
pursuit_csdn3 小时前
LeetCode 1022. Sum of Root To Leaf Binary Numbers
算法·leetcode·深度优先
踩坑记录4 小时前
leetcode hot100 35. 搜索插入位置 medium 二分查找
leetcode
雾岛听蓝5 小时前
C++11新特性(lambda、包装器)
c++·经验分享·笔记
散峰而望6 小时前
C++ 启程:从历史到实战,揭开命名空间的神秘面纱
c语言·开发语言·数据结构·c++·算法·github·visual studio
PingdiGuo_guo6 小时前
C++数据类型、变量常量
开发语言·c++
水饺编程6 小时前
第4章,[标签 Win32] :TextOut 测试案例3代码改编
c语言·c++·windows·visual studio
-海绵东东-6 小时前
哈希表······················
算法·leetcode·散列表
Darkwanderor7 小时前
数据结构 - 并查集的应用
数据结构·c++·并查集
多恩Stone7 小时前
【C++ debug】在 VS Code 中无 Attach 调试 Python 调用的 C++ 扩展
开发语言·c++·python
PingdiGuo_guo7 小时前
C++联合体详解!
开发语言·c++