Skip to content

Commit 59a73b1

Browse files
committed
update: new problem added
1 parent cb7c1c3 commit 59a73b1

File tree

1 file changed

+21
-0
lines changed
  • src/_Problems_/max-consecutive-1s

1 file changed

+21
-0
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function findMaxConsecutive1s(arr) {
2+
let count = 0;
3+
let max = 0;
4+
const length = arr.length;
5+
6+
for (let i = 0; i < length; i += 1) {
7+
if (arr[i] === 1) {
8+
count += 1;
9+
} else if (arr[i] === 0) {
10+
if (count > max) max = count;
11+
count = 0;
12+
}
13+
14+
if (i === length - 1) {
15+
if (count > max) max = count;
16+
}
17+
}
18+
return max;
19+
}
20+
21+
console.log(findMaxConsecutive1s([1, 1, 0, 1]));

0 commit comments

Comments
 (0)