1004. Max Consecutive Ones III最大连续1的个数 III
网址:https://leetcode.com/problems/max-consecutive-ones-iii/
参考:https://leetcode.com/problems/max-consecutive-ones-iii/discuss/247564/JavaC%2B%2BPython-Sliding-Window
- sliding window
- K -= (A[j] == 0);
- 注意判断条件
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的更多相关文章
- [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 ...
- Leetcode 1004. 最大连续1的个数 III
1004. 最大连续1的个数 III 显示英文描述 我的提交返回竞赛 用户通过次数97 用户尝试次数143 通过次数102 提交次数299 题目难度Medium 给定一个由若干 0 和 1 组成 ...
- 1004. 最大连续1的个数 III
1004. 最大连续1的个数 III 给定一个由若干 0 和 1 组成的数组 A,我们最多可以将 K 个值从 0 变成 1 . 返回仅包含 1 的最长(连续)子数组的长度. 示例 1: 输入:A = ...
- LeetCode 1004. Max Consecutive Ones III
原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-iii/ 题目: Given an array A of 0s and 1s, w ...
- [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 ...
- 【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 ...
- 【LeetCode】1004. Max Consecutive Ones III 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 虫取法/双指针 日期 题目地址:https://le ...
- Leetcode 485. 最大连续1的个数
1.题目描述(简单题) 给定一个二进制数组, 计算其中最大连续1的个数. 示例 1: 输入: [1,1,0,1,1,1] 输出: 3 解释: 开头的两位和最后的三位都是连续1,所以最大连续1的个数是 ...
- [LeetCode] Max Consecutive Ones 最大连续1的个数
Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Input: [1, ...
随机推荐
- HDU-6033 Add More Zero
There is a youngster known for amateur propositions concerning several mathematical hard problems. N ...
- JqGrid 自定义子表格 及 自定义Json 格式数据不展示
项目第一次使用JqGrid ,发现功能强大,但由于对他不熟悉,也没有少走弯路,记录一下. 1.引用 <link href="~/Scripts/JqGrid/jqgrid/css/ui ...
- 通用程序返回结果类 ApplicationResult.cs
using System.Collections.Generic; using System.Linq; namespace System { /// <summary> /// 表示应用 ...
- C#连接数据库open函数失败
错误信息:在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Server 已配置为允许远程连接. (provider ...
- VC.文件时间
1. #include <stdio.h> #include <windows.h> void GetFileTimeZ(char *_pcFullFileName, FILE ...
- Linux 安装SSH
●centOS/redhat安装SSH 查询openssh server服务状态:systemctl status sshd 安装sshd命令: yum install openssh-server ...
- Java通过ftp上传文件
首先,pom.xml添加引用 <dependency> <groupId>commons-net</groupId> <artifactId>commo ...
- java调用dll/so文件
大家都知道用C++编写的程序如果用于windows使用则编译为xxx.dll文件,如果是Linux使用则编译为libxxx.so文件.下面将java调用dll/so文件的方法粘出来方便下次使用.此处使 ...
- Servlet JDBC Example
Develop a web application that should have following features. User can register and then login to t ...
- every day a practice —— morning(7)
It is probably because Willow was the last link to her parents and a pastime that goes back to her o ...