Skip to content

Commit da8f60a

Browse files
committed
Solution for: Max cnsecutive ones
1 parent 9080cd4 commit da8f60a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/leetcode/MaxConsecutiveOnes.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package leetcode;
2+
3+
public class MaxConsecutiveOnes {
4+
public int findMaxConsecutiveOnes(int[] nums) {
5+
int cont =0;
6+
int max=0;
7+
for(int i =0; i<nums.length; i++){
8+
if(nums[i]==1) {
9+
cont++;
10+
max= Math.max(max, cont);
11+
}
12+
else{
13+
cont=0;
14+
}
15+
}
16+
return max;
17+
}
18+
}

0 commit comments

Comments
 (0)