We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fa9e690 commit d70f709Copy full SHA for d70f709
scripts/algorithms/M/Max Consecutive Ones/Max Consecutive Ones.java
@@ -0,0 +1,23 @@
1
+// Runtime: 4 ms (Top 25.35%) | Memory: 56.8 MB (Top 44.29%)
2
+class Solution {
3
+ public int findMaxConsecutiveOnes(int[] nums) {
4
+ int max = 0;
5
+ int new_max = 0;
6
+ for(int i=0;i<nums.length;i++){
7
+ if(nums[i]==1)
8
+ {
9
+ max++;
10
+ }
11
+ else{
12
+ if(max>new_max){
13
+ new_max = max;
14
15
+ max = 0;
16
17
18
+ if(max<new_max)
19
+ return new_max;
20
+ else
21
+ return max;
22
23
+}
0 commit comments