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. 3_Phase Portrait_相图_相轨迹

  2. 微信小程序从注册到上线系列

    为了帮助同学们了解注册及上线的整个流程,所以在开发之外,我专门制作了这个从注册到上线流程:本专辑不涉及任何跟开发有关的事情,开发专辑请看:实战开发宝典 以下为具体内容: 从注册到上线系列<一&g ...

  3. Linux 0.11源码阅读笔记-总结

    总结 Linux 0.11主要包含文件管理和进程管理两个部分.进程管理包括内存管理.进程管理.进程间通信模块.文件管理包含磁盘文件系统,打开文件内存数据.磁盘文件系统包括空闲磁盘块管理,文件数据块的管 ...

  4. 升级DLL plugin 到AutoDllPlugin

    为了使打包构建速度加快使用的DLLPlugin,但是我们还是需要手动把dll文件引入文件, HTMLwebpackplugin 结合autoDLLplugin可以自动引入打包文件, 十份地方便

  5. FastAPI(七十三)实战开发《在线课程学习系统》接口开发-- 回复留言

    之前文章分享FastAPI(七十二)实战开发<在线课程学习系统>接口开发-- 留言列表开发,这次我们分享如何回复留言 按照惯例,我们还是去分析这里面的逻辑. 1.判断用户是否登录 2.用户 ...

  6. c++对c的拓展_指针的引用

    套用引用公式:Type & ref =val; 假设:type 类型为int * 由公式得 int * & ref = val; // int * *const ref=&va ...

  7. [源码解析] TensorFlow 分布式环境(8) --- 通信机制

    [源码解析] TensorFlow 分布式环境(8) --- 通信机制 目录 [源码解析] TensorFlow 分布式环境(8) --- 通信机制 1. 机制 1.1 消息标识符 1.1.1 定义 ...

  8. netty系列之:java中的base64编码器

    简介 什么是Base64编码呢?在回答这个问题之前,我们需要了解一下计算机中文件的分类,对于计算机来说文件可以分为两类,一类是文本文件,一类是二进制文件. 对于二进制文件来说,其内容是用二进制来表示的 ...

  9. Grafana中文汉化

    可视化图表 Grafana是一个通用的可视化工具.通过Grafana可以管理用户权限,数据分析,查看,导出,设置告警等. 仪表盘Dashboard 通过数据源定义好可视化的数据来源之后,对于用户而言最 ...

  10. thymeleaf模板使用

    使用模板页面,实现在同一个页面展现不同数据,controller实现页面跳转的时候就不在需要打开新页面