1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 09:59:41 +01:00
LeetCode/cs/longest-subarray-of-1s-after-deleting-one-element.cs

21 lines
456 B
C#
Raw Normal View History

public class Solution {
public int BitToInt(int num) => num == 0 ? 1 : 0;
public int LongestSubarray(int[] nums) {
var longest = 0;
var zeros = 0;
for (int l = 0, r = 0; r < nums.Length; ++r) {
zeros += BitToInt(nums[r]);
for (; zeros > 1; ++l) {
zeros -= BitToInt(nums[l]);
}
longest = Math.Max(longest, r - l);
}
return longest;
}
}