Max Consecutive Ones LeetCode solution in Java

1
class Solution {
2
public int findMaxConsecutiveOnes(int[] nums) {
3
int max = 0;
4
int new_max = 0;
5
for (int i = 0; i < nums.length; i++) {
6
if (nums[i] == 1) {
7
max++;
8
} else {
9
if (max > new_max) {
10
new_max = max;
11
}
12
max = 0;
13
}
14
}
15
if (max < new_max) return new_max;
16
else return max;
17
}
18
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0