We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c3114f4 commit fcd904cCopy full SHA for fcd904c
0487-max-consecutive-ones-ii/max-consecutive-ones-ii.ts
@@ -0,0 +1,20 @@
1
+function findMaxConsecutiveOnes(nums: number[]): number {
2
+ const n = nums.length;
3
+ let left = 0;
4
+ let totalZeros = 0;
5
+ let maxLength = 0;
6
+ for (let right = 0; right < n; right++) {
7
+ const curr = nums[right];
8
+ if (curr === 0) {
9
+ totalZeros++;
10
+ }
11
+ while (totalZeros > 1) {
12
+ if (nums[left] === 0) {
13
+ totalZeros--;
14
15
+ left++;
16
17
+ maxLength = Math.max(maxLength, right - left + 1);
18
19
+ return maxLength;
20
+};
0 commit comments