1493. Longest Subarray of 1's After Deleting One Element Medium

@problem@discussion
#Array#Dynamic Programming#Sliding Window



1/**
2 * [1493] Longest Subarray of 1's After Deleting One Element
3 *
4 * Given a binary array nums, you should delete one element from it.
5 * Return the size of the longest non-empty subarray containing only 1's in the resulting array. Return 0 if there is no such subarray.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [1,1,0,1]
10 * Output: 3
11 * Explanation: After deleting the number in position 2, [1,1,1] contains 3 numbers with value of 1's.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [0,1,1,1,0,1,1,0,1]
16 * Output: 5
17 * Explanation: After deleting the number in position 4, [0,1,1,1,1,1,0,1] longest subarray with value of 1's is [1,1,1,1,1].
18 * 
19 * Example 3:
20 * 
21 * Input: nums = [1,1,1]
22 * Output: 2
23 * Explanation: You must delete one element.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length <= 10^5
29 * 	nums[i] is either 0 or 1.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/
35// discuss: https://leetcode.com/problems/longest-subarray-of-1s-after-deleting-one-element/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn longest_subarray(nums: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1493() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.