LeetCode题解之Max Consecutive Ones
1、题目描述

2、问题分析
遍历一次数组,以每个1 为起点向后数,数到0 时比较当前1的个数和最大1 的个数,然后将遍历的起点放到当前0 的后面。
3、代码
int findMaxConsecutiveOnes(vector<int>& nums) {
int result = ;
if( nums.size() == ) return result;
for( int i = ; i < nums.size() ; i++ ){
if( nums[i] == ){
int j = i;
int num_1 = ;
while( j < nums.size() && nums[j] == ){
num_1++;
j++;
i = j-;
}
if( num_1 > result ){
result = num_1;
}
}
}
return result ;
}
LeetCode题解之Max Consecutive Ones的更多相关文章
- 【leetcode】485. Max Consecutive Ones
problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...
- 【LeetCode】485. Max Consecutive Ones 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...
- LeetCode算法题-Max Consecutive Ones(Java实现)
这是悦乐书的第242次更新,第255篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第109题(顺位题号是485).给定二进制数组,找到此数组中连续1的最大数量.例如: 输 ...
- 【LeetCode】487. Max Consecutive Ones II 解题报告 (C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetco ...
- 【LeetCode】1004. Max Consecutive Ones III 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 虫取法/双指针 日期 题目地址:https://le ...
- 【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 Max Consecutive Ones II
原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...
- LeetCode 1004. Max Consecutive Ones III
原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-iii/ 题目: Given an array A of 0s and 1s, w ...
- [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 ...
随机推荐
- Json.Net 在.Net Core 2.0 中序列化DataSet 问题
使用Asp.Net Core中自带的版本10.0.1 生成一个简单的DataSet DataSet ds2 = new DataSet(); DataTable table = new DataTab ...
- 查漏补缺之开g的正则
当正则表达式开了挂,就会多一个g的修饰符,用于表示全局匹配.然而这个表达式却不仅仅是多了个g这么简单,它的方法也会发生改变.由于之前不是太了解,今天好好捋一下,且听我细细道来. 正则表达式的方法和属性 ...
- 02-04:springboot 访问静态资源
1.SpringBoot从classpath/static的目录下:(目录名称必须叫static,可以理解为根目录为static) 2.servletContext根目录下,进行查找: 在src/ma ...
- 深入浅出zeptojs中tap事件
1.tap事件实现 zepto 源码里面看关于tap的实现方法: $(document).ready(function(){ var now, delta, deltaX = 0, deltaY = ...
- intellij idea 怎么全局搜索--转
https://jingyan.baidu.com/article/29697b9163ac7dab20de3cbf.html intellij idea是一款智能,功能强大的ide,对比eclips ...
- multiset多重集合容器(常用的使用方法总结)
关于C++STL中multiset集合容器的学习,看别人的代码一百遍,不如自己动手写一遍. multiset多重集合容器和set集合容器的使用方法大多相同,不同的是multiset多重集合容器允许重复 ...
- 【WePY小程序框架实战三】-组件传值
[WePY小程序框架实战一]-创建项目 [WePY小程序框架实战二]-页面结构 父子组件传值 静态传值 静态传值为父组件向子组件传递常量数据,因此只能传递String字符串类型. 父组件 (paren ...
- Webhook是什么、怎么理解
Webhook是什么 我们想看看维基老大的解说: A webhook in web development is a method of augmenting or altering the beha ...
- 定时器--Quartz.Net
这次由于项目的需求:什么定时发送邮件通知,定时筛选取消客户下单未支付的订单 重新捡起定时器,在网上翻来找去找到----Quartz.Net老字号了并不表示它就真的老了哦 github:https:// ...
- oracle创建表的方法和一些常用命令
1.主键和外键主键:关系型数据库中的一条记录中有若干个属性,若其中的某一个属性组(注意是组,可以是一个,也可以是多个)能唯一标识一条记录,那么该属性组就是主键外键:关系型数据库表中的一列或者某几列的组 ...