#2750
Ways to Split Array Into Good Subarrays
expert · 1070 · lc medium +32 · verified · 34.8% accepted · 472 likes · top 12%
Description
Given a binary array nums, a subarray is good when it contains exactly one 1. Count the number of ways to partition nums into good subarrays and return that count modulo 109 + 7.
Example 1:
Input: nums = [0,1,0,0,1]
Output: 3
Explanation: There are 3 ways to split nums into good subarrays:
- [0,1] [0,0,1]
- [0,1,0] [0,1]
- [0,1,0,0] [1]
Example 2:
Input: nums = [0,1,0]
Output: 1
Explanation: There is 1 way to split nums into good subarrays:
- [0,1,0]
Code
1
2
3