Class Solution
java.lang.Object
g0901_1000.s0930_binary_subarrays_with_sum.Solution
930 - Binary Subarrays With Sum.<p>Medium</p>
<p>Given a binary array <code>nums</code> and an integer <code>goal</code>, return <em>the number of non-empty <strong>subarrays</strong> with a sum</em> <code>goal</code>.</p>
<p>A <strong>subarray</strong> is a contiguous part of the array.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> nums = [1,0,1,0,1], goal = 2</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> The 4 subarrays are bolded and underlined below:</p>
<p>[<strong>1,0,1</strong> ,0,1]</p>
<p>[<strong>1,0,1,0</strong> ,1]</p>
<p>[1, <strong>0,1,0,1</strong> ]</p>
<p>[1,0, <strong>1,0,1</strong> ]</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> nums = [0,0,0,0,0], goal = 0</p>
<p><strong>Output:</strong> 15</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= nums.length <= 3 * 10<sup>4</sup></code></li>
<li><code>nums[i]</code> is either <code>0</code> or <code>1</code>.</li>
<li><code>0 <= goal <= nums.length</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
numSubarraysWithSum
public int numSubarraysWithSum(int[] nums, int goal)
-