1004. 最大连续1的个数 III

1004. 最大连续1的个数 III


题目链接:1004. 最大连续1的个数 III

代码如下:

cpp 复制代码
class Solution 
{
public:
    int longestOnes(vector<int>& nums, int k) 
    {
        int res=0,left=0,count0=0; 0 变成 1,用来统计 count0
        for(int right=0;right<nums.size();right++)
        {
            if(nums[right]==0)  {count0++;}
            while(count0>k)
            {
                if(nums[left]==0)   {count0--;}
                left++;
            }
            res=max(res,right-left+1);
        }
        return res;
    }
};
相关推荐
我不会插花弄玉3 小时前
13.多路转接epoll【由浅入深-网络】
网络·c++·epoll
郝学胜-神的一滴5 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus6 小时前
C++ explicit 关键字工程实践
开发语言·c++
AIgorithmGEEK8 小时前
std::unordered_map 与 std::unordered_set:接口、算法技巧与权衡 (速查)
c++·算法·哈希表·负载因子·桶·unordered_map·unordered_set
一拳一个呆瓜10 小时前
【STL】头文件:<cmath>
c++·stl
草莓熊Lotso11 小时前
【C++ 基于微服务的即时通讯系统】ElasticSearch 用户数据管理实现
linux·数据库·c++·elasticsearch·微服务·架构
慧都产品智能化11 小时前
Qt 开发 CAD/CAM 工序表的隐性成本分析
c++·qt·qt5·qt6.3
eggwyw13 小时前
linux下的C\C++多进程多线程编程实例详解
开发语言·c++
青少儿编程课堂14 小时前
第十八届蓝桥杯青少组图形化真题 + 全国青少年信息素养大赛 + 电子学会图形化考级:校园泡泡堂大挑战解析
c++·python·算法·bfs·信息学竞赛
小七在进步15 小时前
string的实现(3)
开发语言·c++·笔记·visual studio