Skip to content

Commit 6c084c8

Browse files
committed
Add solution for 483.
1 parent 1a69fae commit 6c084c8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

0483.max-consecutive-ones.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var findMaxConsecutiveOnes = function(nums) {
6+
let max = 0;
7+
let localMax = 0;
8+
for (let i = 0; i < nums.length; i++) {
9+
if (nums[i] === 1) {
10+
localMax++;
11+
} else {
12+
localMax = 0;
13+
}
14+
15+
max = Math.max(max, localMax);
16+
}
17+
18+
return max;
19+
};

0 commit comments

Comments
 (0)