Description
Given a binary array nums, return the size of the longest non-empty subarray containing only 1s after deleting exactly one element.
Examples
Input:
nums = [1,1,0,1]Output:
3Explanation:
Delete 0 for [1,1,1].
Input:
nums = [1,1,1,0,0,1,1,1]Output:
3Explanation:
Deleting one 0 can only join adjacent runs across a single zero. Here the best run after deleting one 0 has length 3.
Input:
nums = [0,0,0]Output:
0Explanation:
Since the array contains only 0s, deleting one element still leaves no 1s, so the answer is 0.
Constraints
- •
1 ≤ nums.length ≤ 10⁵