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的更多相关文章

  1. 【leetcode】485. Max Consecutive Ones

    problem 485. Max Consecutive Ones solution1: class Solution { public: int findMaxConsecutiveOnes(vec ...

  2. 【LeetCode】485. Max Consecutive Ones 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 [LeetCo ...

  3. LeetCode算法题-Max Consecutive Ones(Java实现)

    这是悦乐书的第242次更新,第255篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第109题(顺位题号是485).给定二进制数组,找到此数组中连续1的最大数量.例如: 输 ...

  4. 【LeetCode】487. Max Consecutive Ones II 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 日期 题目地址:https://leetco ...

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

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

  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 Max Consecutive Ones II

    原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...

  8. LeetCode 1004. Max Consecutive Ones III

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

  9. [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 ...

随机推荐

  1. storm_常用命令

    1)nimbus:启动nimbus守护进程        storm nimbus 2)supervisor:启动supervisor守护进程        storm supervisor 3)ui ...

  2. Android_对android虚拟机的理解,包括内存管理机制垃圾回收机制。dalvik和art区别

    虚拟机很小,空间很小,谈谈移动设备的虚拟机的大小限制 16M ,谈谈加载图片的时候怎么处理大图片的,outmemoryExceptionBitmapFactory.option 垃圾回收,没有引用的对 ...

  3. linux下安装lnmp环境

    安装nginx   1 检查是否安装该程序: which nginx           #查看nginx是否存在 which php             #查看php是否存在 which mys ...

  4. 哨兵/sentinel:在算法设计中的应用

    哨兵(sentinel)昨天看算法导论里对哨兵的描述后,觉得这是一种很有意思的编程思想.哨兵是一个哑对象.一般哨兵不存放任何数据,但其结构体与其他有用的元素一致.正如其字面意思,哨兵是在边界保卫祖国的 ...

  5. Redis+Jedis封装工具类

    package com.liying.monkey.core.util; import java.io.IOException; import java.util.ArrayList; import ...

  6. 腾讯、百度、网易游戏、华为Offer及笔经面经

    原文出处:http://bbs.yingjiesheng.com/forum.php?mod=viewthread&tid=1011893&fromuid=1745894 应届生上泡了 ...

  7. RecyclerView 使用指南

    最近看了很多 RecyclerView 的使用文章,一直晕乎乎的,完全不知道套路是啥.很多人都是直接上代码,但是却没有详细说明代码的使用,于是打算自己写写,理理思路.顺便帮助那些正在学习 Androi ...

  8. EasyUI 添加一行的时候 行号出现负数的解决方案

    原因是:在jquery_easyui.js 看方法 insertRow : function(_736, _737, row) 以下小代码算行号,if (opts.pagination) { _73c ...

  9. [日常] Go语言圣经-可变参数习题

    1.参数数量可变的函数称为为可变参数函数,例子就是fmt.Printf和类似函数2.参数列表的最后一个参数类型之前加上省略符号“...”3.虽然在可变参数函数内部,...int 型参数的行为看起来很像 ...

  10. java多线程框架

    JDK5中的一个亮点就是将Doug Lea的并发库引入到Java标准库中.Doug Lea确实是一个牛人,能教书,能出书,能编码,不过这在国外还是比较普遍的,而国内的教授们就相差太远了. 一般的服务器 ...