描述

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

Example 1:

Input: [1,1,0,1,1,1]

Output: 3

Explanation: 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

分析

太简单了,一分钟ac

代码如下:

class Solution {
public:
int findMaxConsecutiveOnes(vector<int>& nums) {
if(nums.size() == 0)return 0;
int max = 0;
int length = 0;
for(int i = 0; i != nums.size(); ++i){
if(nums[i] == 1){
++length;
max = length > max ? length : max;
}else{
length = 0;
}
}
return max;
}
};

最新文章

  1. Revert R12.1.3 Homepage Layout to Link Style as in R12.1.1 or 11i
  2. [BZOJ2730][HNOI2012]矿场搭建(求割点)
  3. h5交互元素details标签
  4. Codeforces Beta Round #95 (Div. 2) D.Subway
  5. WordPress搬家教程:换空间与换域名
  6. POSIX线程
  7. Asp.net MVC23 使用Areas功能的常见错误
  8. web和winform的MD5加密
  9. apt系统中sources.list文件的解析
  10. oracle数据库删除数据Delete语句和Truncate语句的对比
  11. WebService之CXF注解报错(一)
  12. RabbitMQ消息队列(二):”Hello, World“
  13. codeforces 1153 D
  14. SQL CREATE DATABASE 语句
  15. Cordova入门系列(四)自定义Cordova插件--showToast
  16. 用junit对java代码进行测试,需要注意
  17. Luogu 2590 [ZJOI2008]树的统计 / HYSBZ 1036 [ZJOI2008]树的统计Count (树链剖分,LCA,线段树)
  18. QT,QT SDK, QT Creator 区别
  19. centos配置ssh免密码登录
  20. Linux 基础教程 43-su和sudo命令

热门文章

  1. gopacket 在 windows 上面遇到的问题
  2. Spring Boot 集成 Swagger生成接口文档
  3. Spring Boot的配置文件-yml文件的集合配置方式
  4. AS3动画效果常用公式
  5. 最简容器化动手小实践——再战flappybird
  6. Centos7+puppet+foreman,模板介绍
  7. Linux环境实现python远程可视编程
  8. 关于MQ的几件小事(五)如何保证消息按顺序执行
  9. DbTemplate
  10. [LeetCode] 1029. 两地调度 ☆(贪心)