485. Max Consecutive Ones
来源:互联网 发布:java 静态单例模式 编辑:程序博客网 时间:2024/06/05 17:25
485. Max Consecutive Ones
题目
Given a binary array, find the maximum number of consecutive 1s in this array.
Example 1:
Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s. The maximum number of consecutive 1s is 3.
Note:
The input array will only contain 0 and 1.
The length of input array is a positive integer and will not exceed 10,000
翻译
给定二进制数组,找到此数组中连续1的最大数。
示例1:
输入: [1,1,0,1,1,1]
输出: 3
说明:前两位数字或后三位数字是连续的1s。
连续1的最大数量为3。
注意:
输入数组只包含0和1。
输入数组的长度为正整数,不超过10,000
解题思路
public class Solution { public int findMaxConsecutiveOnes(int[] nums) { if(nums.length<1) return 0; int count=0; int result=0; for(int i=0;i<nums.length;i++){ if(nums[i]==1){ count++; }else{ if(count>result) result=count; count=0; } } if(count>result) result=count; return result; }}
欢迎加入中科院开源软件自习室:631696396
阅读全文
0 0
- 485. Max Consecutive Ones*
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485. Max Consecutive Ones
- 485.Max Consecutive Ones
- 自定义歌词展示控件
- codeforces 417
- IDEA中使用JDBC
- Python中List和Tuple类型
- 二叉树的建立及遍历
- 485. Max Consecutive Ones
- 腾讯直播——推流SDK(Android)
- python操作Mongodb数据库
- HDU 4574 Bombs DFS
- Cef3:vs2015开发环境搭建
- 模拟题 I
- 35. Search Insert Position
- c++邻接矩阵存储图
- hibernate缓存详解