package leetcode;

/**
 * https://leetcode.com/problems/binary-subarrays-with-sum/
 */
public class Problem930 {
    public int numSubarraysWithSum(int[] A, int S) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem930 prob = new Problem930();
        System.out.println(prob.numSubarraysWithSum(new int[]{1, 0, 1, 0, 1}, 2)); // 4
    }
}

@@ -171,32 +171,709 @@
     
-// TODO%0A        return 0
+int sum = 0;%0A        int%5B%5D sums = new int%5BA.length%5D;%0A        for (int i = 0; i %3C A.length; i++) %7B%0A            sum += A%5Bi%5D;%0A            sums%5Bi%5D += sum;%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C sums.length; i++) %7B%0A            if (sums%5Bi%5D == S) %7B%0A                answer++;%0A            %7D%0A            if (sums%5Bi%5D %3E= S) %7B%0A                int j = 0;%0A                while (j %3C i) %7B%0A                    int diff = sums%5Bi%5D - sums%5Bj%5D;%0A                    if (diff == S) %7B%0A                        answer++;%0A                    %7D else if (diff %3C S) %7B%0A                        break;%0A                    %7D%0A                    j++;%0A                %7D%0A            %7D%0A        %7D%0A        return answer
 ;%0A  
@@ -1054,16 +1054,104 @@
 ); // 4%0A
+        System.out.println(prob.numSubarraysWithSum(new int%5B%5D%7B0, 1, 1, 1, 1%7D, 3)); // 3%0A
     %7D%0A%7D%0A

Update problem 930