Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c146e39

Browse files
committed
added task #485 solution
1 parent fc9740c commit c146e39

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/task_485/Solution.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package task_485;
2+
3+
public class Solution {
4+
5+
public static void main(String[] args) {
6+
System.out.println(findMaxConsecutiveOnes(new int[] {1,1,0,1,1,1}));
7+
}
8+
9+
public static int findMaxConsecutiveOnes(int[] nums) {
10+
int consecutiveOnesCounter = 0;
11+
int currentCounter = 0;
12+
for (int i = 0; i < nums.length; i++) {
13+
if (nums[i] == 0) {
14+
currentCounter = 0;
15+
} else {
16+
currentCounter++;
17+
}
18+
if (consecutiveOnesCounter < currentCounter) {
19+
consecutiveOnesCounter = currentCounter;
20+
}
21+
}
22+
return consecutiveOnesCounter;
23+
}
24+
25+
}

0 commit comments

Comments
 (0)