Skip to content

Commit 9fae430

Browse files
authored
Create 485. Max Consecutive Ones.java
1 parent b9ab3a4 commit 9fae430

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

485. Max Consecutive Ones.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution {
2+
public int findMaxConsecutiveOnes(int[] nums) {
3+
int max = 0, cur = 0;
4+
5+
for (int i = 0; i < nums.length; i++) {
6+
if (nums[i] == 0) {
7+
cur = 0;
8+
} else {
9+
cur += 1;
10+
if (cur > max) {
11+
max = cur;
12+
}
13+
}
14+
}
15+
16+
return max;
17+
}
18+
}

0 commit comments

Comments
 (0)