网址:https://leetcode.com/problems/max-consecutive-ones-iii/

参考:https://leetcode.com/problems/max-consecutive-ones-iii/discuss/247564/JavaC%2B%2BPython-Sliding-Window

  1. sliding window
  2. K -= (A[j] == 0);
  3. 注意判断条件
 class Solution {
public:
int longestOnes(vector<int>& A, int K) {
int i = ;
int ans = ;
for(int j = ; j<A.size(); j++)
{
K -= (A[j] == );
if(K < )
{
K += (A[i] == );
i++;
}
ans = j - i + ;
}
return ans;
}
};

1004. Max Consecutive Ones III最大连续1的个数 III的更多相关文章

  1. [LeetCode] Max Consecutive Ones II 最大连续1的个数之二

    Given a binary array, find the maximum number of consecutive 1s in this array if you can flip at mos ...

  2. Leetcode 1004. 最大连续1的个数 III

    1004. 最大连续1的个数 III  显示英文描述 我的提交返回竞赛   用户通过次数97 用户尝试次数143 通过次数102 提交次数299 题目难度Medium 给定一个由若干 0 和 1 组成 ...

  3. 1004. 最大连续1的个数 III

    1004. 最大连续1的个数 III 给定一个由若干 0 和 1 组成的数组 A,我们最多可以将 K 个值从 0 变成 1 . 返回仅包含 1 的最长(连续)子数组的长度. 示例 1: 输入:A = ...

  4. LeetCode 1004. Max Consecutive Ones III

    原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-iii/ 题目: Given an array A of 0s and 1s, w ...

  5. [Swift]LeetCode1004. 最大连续1的个数 III | Max Consecutive Ones III

    Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of the lo ...

  6. 【leetcode】1004. Max Consecutive Ones III

    题目如下: Given an array A of 0s and 1s, we may change up to K values from 0 to 1. Return the length of ...

  7. 【LeetCode】1004. Max Consecutive Ones III 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 虫取法/双指针 日期 题目地址:https://le ...

  8. Leetcode 485. 最大连续1的个数

    1.题目描述(简单题) 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 ...

  9. [LeetCode] Max Consecutive Ones 最大连续1的个数

    Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...

随机推荐

  1. 微服务架构与实践3_api

    场景分析 描述产品服务,基于REST的接口 表述性状态转移(Representational State Transfer,REST) 任务拆分 将整体要做的工作内容划分成小的任务: 统一时间聚焦一个 ...

  2. Levenshtein Distance,判断字符串的相似性

    private int LevenshteinDistance(string s1,string s2,int maxValue) { if (s1 == null|| s1.Length == 0) ...

  3. 每天一个小程序—0014题(txt 转 Excel)

    基础知识:Excel文件的后缀有xls和xlsx,前者是针对2003版本的,2007及其之后的版本是xlsx. 在python中对于这两种不同后缀的文件有不同的库来处理,对于xls用wlrd.xlwt ...

  4. 如何创建R包并将其发布在 CRAN / GitHub 上--转载

    转载--https://www.analyticsvidhya.com/blog/2017/03/create-packages-r-cran-github/ 什么是 R 包?我开始创建 R 包的原因 ...

  5. sql 中常见的控制流语句

    控制流语句:1 begin .....end  2 if ...else  例如:if exists (select * from 表名称 ) begin selct * from  表名称 end  ...

  6. 设计模式(四) Factory Pattern工厂模式

    核心: 实例化对象,实现创建者和调用者的分离 简单工厂模式 工厂方法模式 抽象工厂模式 面对对象设计的基本原则: ocp(open closed principle) 开闭原则:一个软件的实体应当对拓 ...

  7. Django 国际化和本地化

    所谓的国际化,是指使用不同语言的用户在访问同一个网站页面时能够看到符合其自身语言的文本页面. 国际化的基本原理是: 浏览器通过LANGUAGE_CODE在HTTP请求头中告诉网站后台服务器用户所需要的 ...

  8. requests:json请求中中文乱码处理

    requests库中,在处理json格式的请求时调用的json.dumps方法参数ensure_ascii默认为True.表示序列化时对中文默认使用的ascii编码.如果想要显示中文,则将此参数的值改 ...

  9. eclipse导入项目文件以及 import项目文件后有个红色感叹号

    eclipse导入项目文件 步骤:File —>Import—>General—>Existing Projects into Workspace 然后进去选择项目文件的具体路径即可 ...

  10. Python全栈开发-Day9-线程/GIL/事件/队列

    本节内容 进程与线程的概念 Python threading 模块 GIL——global interpreter lock Mutex互斥锁(线程锁) Semaphore信号量 Events事件 Q ...