Presum or accumulate
1 min readDec 6, 2019
For the problem listed above, 930. Binary Subarrays With Sum. We can use the itertools.accumulate to solve the problem as shown below. We should be careful when encountering with [0 ,0 , 0, 0] and S=0 case. As this method will fail in this case.
accumulate
Or we can use presum. Here is the code from the link below. Credit give to lee251.