1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
LeetCode/cs/max-consecutive-ones-iii.cs

23 lines
486 B
C#
Raw Normal View History

public class Solution {
public int LongestOnes(int[] nums, int k) {
int maxLength = 0;
int zeros = 0;
for (int i = 0, j = 0; j < nums.Length; ++j) {
if (nums[j] == 0) {
++zeros;
}
for (; zeros > k; ++i) {
if (nums[i] == 0) {
--zeros;
}
}
maxLength = Math.Max(maxLength, j - i + 1);
}
return maxLength;
}
}