In an array A
of 0
s and 1
s, how many non-empty subarrays have sum S
?
Example 1:
Input: A = [1,0,1,0,1], S = 2 Output: 4 Explanation: The 4 subarrays are bolded below: [1,0,1,0,1] [1,0,1,0,1] [1,0,1,0,1] [1,0,1,0,1]
Note:
<li><code>A.length <= 30000</code></li>
<li><code>0 <= S <= A.length</code></li>
<li><code>A[i]</code> is either <code>0</code> or <code>1</code>.</li>