Question

485. Max Consecutive Ones

Solution

题目大意:给一个数组,取连续1的最大长度

思路:遍历数组,连续1就加1,取最大

Java实现:

public int findMaxConsecutiveOnes(int[] nums) {
if (nums == null) return 0;
int result = 0;
int tmp = 0;
for (int i : nums) {
if (i == 1) {
tmp++;
} else {
result = tmp > result? tmp: result;
tmp = 0;
}
}
result = tmp > result? tmp: result;
return result;
}

485. Max Consecutive Ones - LeetCode的更多相关文章

  1. 【leetcode】485. Max Consecutive Ones

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

  2. 485. Max Consecutive Ones【easy】

    485. Max Consecutive Ones[easy] Given a binary array, find the maximum number of consecutive 1s in t ...

  3. 485. Max Consecutive Ones最长的连续1的个数

    [抄题]: Given a binary array, find the maximum number of consecutive 1s in this array. Example 1: Inpu ...

  4. 485. Max Consecutive Ones@python

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

  5. LeetCode 485. Max Consecutive Ones (最长连续1)

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

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

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

  7. 8. leetcode 485. Max Consecutive Ones

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

  8. (双指针) leetcode 485. Max Consecutive Ones

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

  9. LeetCode 485 Max Consecutive Ones 解题报告

    题目要求 Given a binary array, find the maximum number of consecutive 1s in this array. 题目分析及思路 给定一个01数组 ...

随机推荐

  1. canvas动画—圆形扩散、运动轨迹

    介绍 在ECharts中看到过这种圆形扩散效果,类似css3,刚好项目中想把它用上,but我又不想引入整个echart.js文件,更重要的是想弄明白它的原理,所以自己动手.在这篇文章中我们就来分析实现 ...

  2. js修改html中class属性

    document.getElementById("tr").setAttribute("class","styleclass"); 其中  ...

  3. HashMap和ConcurrentHashMap的原理和实现

    一.线程不安全的HashMap 多线程环境下,使用HashMap进行put操作会引起死循环(jdk1.7 Entry链表形成环形数据结构),导致CPU利用率接近100%. 结构:数组 table[]+ ...

  4. 在ios里面返回上一级报错问题

    $("#backPrev").attr("href","javascript:void(0);").click(function(){    ...

  5. 计算机网络 TCP 四次挥手过程和状态变迁

    客户端打算关闭连接,此时会发送一个 TCP 首部 FIN 标志位被置为 1 的报文,也即 FIN 报文,之后客户端进入 FIN_WAIT_1 状态. 服务端收到该报文后,就向客户端发送 ACK 应答报 ...

  6. linux3种安装软件、yum仓库、防火墙、乱码

    Linux中安装软件的三种方式 1.哪三种方式? rpm安装 yum安装 源代码编译安装 2.区别 rpm安装类似于windows中的安装包,下载下来之后直接安装.缺点是不能自己解决依赖. yum安装 ...

  7. DOM 对象的重点核心

    概述 :  文档对象模型(Document Object Model,简称DOM ),是W3C组织推荐的处理可扩展标记语言 (HTML或者XML)的标准编程接口. W3C已经定义了一系列的DOM接口, ...

  8. Envoy熔断限流实践(一)基于Rainbond插件实现熔断

    Envoy 可以作为 Sevice Mesh 微服务框架中的代理实现方案,Rainbond 内置的微服务框架同样基于 Envoy 实现.本文所描述的熔断实践基于 Rainbond 特有的插件机制实现. ...

  9. 合并csv文件保存到一个csv文件中-保留表头

    主要实现功能: 在同一文件夹下的所有csv文件全部合并到同一个csv文件中,并将csv文件的表头保留 1 import os 2 import pandas as pd 3 path = os.get ...

  10. VSCode 前端常用插件集合

    Visual Studio Code 是由微软开发的一款免费.跨平台的文本编辑器.由于其卓越的性能和丰富的功能,它很快就受到了大家的喜爱. 但工欲善其事必先利其器,以下是本人为前端开发收集的常用的vs ...