2750. Ways to Split Array Into Good Subarrays Medium

@problem@discussion
#Array#Math#Dynamic Programming



1/**
2 * [2750] Ways to Split Array Into Good Subarrays
3 *
4 * You are given a binary array nums.
5 * A subarray of an array is good if it contains exactly one element with the value 1.
6 * Return an integer denoting the number of ways to split the array nums into good subarrays. As the number may be too large, return it modulo 10^9 + 7.
7 * A subarray is a contiguous non-empty sequence of elements within an array.
8 *  
9 * <strong class="example">Example 1:
10 * 
11 * Input: nums = [0,1,0,0,1]
12 * Output: 3
13 * Explanation: There are 3 ways to split nums into good subarrays:
14 * - [0,1] [0,0,1]
15 * - [0,1,0] [0,1]
16 * - [0,1,0,0] [1]
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: nums = [0,1,0]
21 * Output: 1
22 * Explanation: There is 1 way to split nums into good subarrays:
23 * - [0,1,0]
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length <= 10^5
29 * 	0 <= nums[i] <= 1
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/ways-to-split-array-into-good-subarrays/
35// discuss: https://leetcode.com/problems/ways-to-split-array-into-good-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn number_of_good_subarray_splits(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_2750() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.