java.lang.Object
g2701_2800.s2750_ways_to_split_array_into_good_subarrays.Solution

public class Solution extends Object
2750 - Ways to Split Array Into Good Subarrays.<p>Medium</p> <p>You are given a binary array <code>nums</code>.</p> <p>A subarray of an array is <strong>good</strong> if it contains <strong>exactly</strong> <strong>one</strong> element with the value <code>1</code>.</p> <p>Return <em>an integer denoting the number of ways to split the array</em> <code>nums</code> <em>into <strong>good</strong> subarrays</em>. As the number may be too large, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p>A subarray is a contiguous <strong>non-empty</strong> sequence of elements within an array.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [0,1,0,0,1]</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong> There are 3 ways to split nums into good subarrays:</p> <ul> <li>[0,1] [0,0,1]</li> <li>[0,1,0] [0,1]</li> <li>[0,1,0,0] [1]</li> </ul> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [0,1,0]</p> <p><strong>Output:</strong> 1</p> <p><strong>Explanation:</strong> There is 1 way to split nums into good subarrays: - [0,1,0]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>0 <= nums[i] <= 1</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numberOfGoodSubarraySplits

      public int numberOfGoodSubarraySplits(int[] nums)