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;
    }
};
相关推荐
木井巳5 小时前
【递归算法】组合总和
java·算法·leetcode·决策树·深度优先·剪枝
coding者在努力5 小时前
被n整除的n位数
c++·算法
赵药师5 小时前
Win11下的VS2022 配置RGBD435i 相机
c++·vs2022·windows11·rgbd435i
量子炒饭大师6 小时前
【C++ 进阶】Cyber霓虹掩体下的代码拟态——【面向对象编程 之 多态】一文带你搞懂C++面向对象编程中的三要素之一————多态!
开发语言·c++·多态
伴我与影6 小时前
【记录】复现论文 Dftpav
c++·docker
Hical_W6 小时前
深入学习CPP17_PMR
c++·学习
计算机安禾7 小时前
【数据结构与算法】第42篇:并查集(Disjoint Set Union)
c语言·数据结构·c++·算法·链表·排序算法·深度优先
吃着火锅x唱着歌7 小时前
LeetCode 150.逆波兰表达式求值
linux·算法·leetcode
阿Y加油吧7 小时前
两道中等 DP 题拆解:打家劫舍 & 完全平方数
算法·leetcode·动态规划
苕皮蓝牙土豆8 小时前
Qt图形视图框架入门:坐标系统与鼠标事件处理详解
c++·qt