leetcode[Max Consecutive Ones]//待整理多种解法
来源:互联网 发布:linux执行命令的过程 编辑:程序博客网 时间:2024/05/16 23:46
解法一:
public class Solution { public int findMaxConsecutiveOnes(int[] nums) { int max = 0; int count = 0; for(int i = 0; i < nums.length; i++){ if(nums[i] == 1){ count++; } if(nums[i] == 0){//当为0时就清零即可,开启新的一段,并计算max max = Math.max(max, count); count = 0; } } //最后还要统计一次,因为防止后面直接结束了 max = Math.max(max, count); return max; }}
阅读全文
0 0
- leetcode[Max Consecutive Ones]//待整理多种解法
- LEETCODE--Max Consecutive Ones
- LeetCode: Max Consecutive Ones
- 【leetcode】Max Consecutive Ones
- LeetCode:Max Consecutive Ones
- LeetCode Max Consecutive Ones
- LeetCode Max Consecutive Ones
- leetCode-Max Consecutive Ones
- leetcode [Path Sum]//待整理多种解法
- leetcode [Majority Element]//待整理多种解法
- leetcode [Rotate Array]//待整理多种解法
- leetcode [Reverse Bits]//待整理多种解法
- leetcode [Happy Number]//待整理多种解法
- leetcode [Isomorphic Strings]//待整理多种解法
- leetcode [Contains Duplicate]//待整理多种解法
- leetcode[Add Digits]//待整理多种解法
- leetcode[Ugly Number]//待整理多种解法
- leetcode[Missing Number]//待整理多种解法
- Excel在统计分析中的应用—第四章—数据库统计函数与数据透视表-Part2-(数据库统计函数)
- 洛谷P1197 星球大战
- 用树莓派改装电风扇及实现Android遥控
- linux 内存管理概述
- 【谨记】PCB画板子的正确步骤(说多了,都是泪啊!)
- leetcode[Max Consecutive Ones]//待整理多种解法
- LeetCode 258. Add Digits
- Caffe2 入门教程
- 重载和重写的区别
- Java 基本数据类型与其包装数据类型以及字符串(String)之间的转换问题
- IntelliJ IDEA搭建SpringBoot应用
- Unity3D之UI设计
- pat-a1110. Complete Binary Tree (25)
- 字符串右旋 、 字符串去重