Skip to content

Commit a4e8f4c

Browse files
committed
MaxConsecutiveOnesSln
1 parent 4f98d15 commit a4e8f4c

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* ==============================================================================
2+
* 功能描述:ThirdMaximumNumber
3+
* 创 建 者:gz
4+
* 创建日期:2017/4/21 8:25:57
5+
* ==============================================================================*/
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Text;
10+
// // Given a binary array, find the maximum number of consecutive 1s in this array.
11+
12+
// // Example 1:
13+
14+
// // Input: [1,1,0,1,1,1]
15+
// // Output: 3
16+
// // Explanation: The first two digits or the last three digits are consecutive 1s.
17+
// // The maximum number of consecutive 1s is 3.
18+
namespace Array.Lib
19+
{
20+
/// <summary>
21+
/// #485. Max Consecutive Ones
22+
/// </summary>
23+
public int FindMaxConsecutiveOnes(int[] nums) {
24+
int ito1=0;
25+
int max = 0;
26+
foreach(var item in nums){
27+
if(item==1){
28+
ito1++;
29+
if(max<ito1)
30+
max = ito1;
31+
}
32+
else
33+
ito1=0;
34+
}
35+
return max;
36+
}
37+
}

0 commit comments

Comments
 (0)