Binary Subarrays With Sum
In an array A of 0s and 1s, how many non-empty subarrays have sum S?
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]
- A.length <= 30000
- 0 <= S <= A.length
- A[i] is either 0 or 1.
Credits To: leetcode.com
Leave me comments, if you have better ways to solve.
- Solution: XXX
Walk Through Testdata
// Blog link: https://code.dennyzhang.com/binary-subarrays-with-sum