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. background-clip 和 background-origin

    下面都是我自己的理解, 如果有不对的地方, 还请大家帮忙指出.下面是在 chrome 浏览器上测试的 background-clip 和 background-origin 先说说background ...

  2. es6-Set与Map

    se5中的set与map 在est5中开发者使用对象属性来模拟.set多用于检查键的存在,map多用于提取数据. { let set = Object.create(null) set.foo = t ...

  3. 使用 ssm 实现登录日志记录

    使用 ssm 实现登录日志记录 学习总结 一.基础准备 1. 实现效果 2. 数据表 2.1 登陆日志信息表 2.3 员工表 二.代码实现 1. SysLogLogin 实体类 2. LogAspec ...

  4. 基于node实现一个简单的脚手架工具(node控制台交互项目)

    实现控制台输入输出 实现文件读写操作 全原生实现一个简单的脚手架工具 实现vue-cli2源码 一.实现控制台输入输出 关于控制台的输入输出依然是基于node进程管理对象process,在proces ...

  5. PostgreSQL执行计划:Bitmap scan VS index only scan

    之前了解过postgresql的Bitmap scan,只是粗略地了解到是通过标记数据页面来实现数据检索的,执行计划中的的Bitmap scan一些细节并不十分清楚.这里借助一个执行计划来分析bitm ...

  6. XShell免费版的安装配置教程以及使用教程(超级详细)

    ​一. XShell的作用 XShell可以在Windows界面下来访问远端不同系统下的服务器,从而比较好的达到远程控制终端的目的.它支持 RLOGIN.SFTP.SERIAL.TELNET.SSH2 ...

  7. Redis 未授权访问漏洞【原理扫描】修复方法

    漏洞类型 主机漏洞 漏洞名称/检查项 Redis 配置不当可直接导致服务器被控制[原理扫描] 漏洞名称/检查项 Redis 未授权访问漏洞[原理扫描] 加固建议 防止这个漏洞需要修复以下三处问题 第一 ...

  8. k8s pod故障分类与排查

    一.Pod故障状态基本有几种Pod状态 处于PendingPod状态 处于WaitingPod状态 处于ContainerCreatingPod状态 ImagePullBackOffPod状态 Cra ...

  9. SpringMVC快速使用——基于注解

    SpringMVC快速使用--基于注解 1.引入依赖 <!-- 定义Spring版本 --> <properties> <spring.verson>5.3.8&l ...

  10. Java基础语法01——变量与运算符

    本文是对Java基础语法的第一部分的学习,包括注释:标识符的命名规则与规范:变量的数据类型分类以及转换:以及六种运算符(算术.赋值.比较.逻辑.三元和位运算符).