package leetcode;

/**
 * https://leetcode.com/problems/continuous-subarray-sum/
 */
public class Problem523 {
    public boolean checkSubarraySum(int[] nums, int k) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem523 prob = new Problem523();
        System.out.println(prob.checkSubarraySum(new int[]{23, 2, 4, 6, 7}, 6)); // true
        System.out.println(prob.checkSubarraySum(new int[]{23, 2, 6, 4, 7}, 6)); // true
    }
}

@@ -173,24 +173,559 @@
     
-// TODO%0A
+Boolean%5B%5D%5B%5D memo = new Boolean%5Bnums.length + 1%5D%5Bnums.length + 1%5D;%0A        return checkSubarraySum(nums, k, 0, nums.length, memo);%0A    %7D%0A%0A    private static boolean checkSubarraySum(int%5B%5D nums, int k, int i, int j, Boolean%5B%5D%5B%5D memo) %7B%0A        if (i %3E= j) %7B%0A            return false;%0A        %7D%0A        if (j - i == 1) %7B%0A            return false;%0A        %7D%0A        int sum = 0;%0A        for (int x = i; x %3C j; x++) %7B%0A            sum += nums%5Bx%5D;%0A        %7D%0A        if (sum == 0 && k == 0) %7B%0A            return true;%0A        %7D%0A        if (k == 0) %7B%0A 
         
 retu
@@ -712,32 +712,35 @@
 = 0) %7B%0A         
+   
 return false;%0A  
@@ -745,276 +745,1123 @@
     
-%7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem523 prob = new Problem523();%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 4, 6, 7%7D, 6)); // true%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 6, 4, 7%7D, 6)); // tru
+    %7D%0A        if (sum %25 k == 0) %7B%0A            return true;%0A        %7D%0A        if (memo%5Bi%5D%5Bj%5D != null) %7B%0A            return memo%5Bi%5D%5Bj%5D;%0A        %7D%0A        boolean a = checkSubarraySum(nums, k, i + 1, j, memo);%0A        boolean b = checkSubarraySum(nums, k, i, j - 1, memo);%0A        boolean c = checkSubarraySum(nums, k, i + 1, j - 1, memo);%0A        boolean result = a %7C b %7C c;%0A        memo%5Bi%5D%5Bj%5D = result;%0A        return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem523 prob = new Problem523();%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 4, 6, 7%7D, 6)); // true%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 6, 4, 7%7D, 6)); // true%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 6, 4, 8%7D, 6)); // true%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B1, 2, 3%7D, 4)); // false%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B23, 2, 6, 4, 7%7D, 0)); // false%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B0, 0%7D, 0)); // true%0A        System.out.println(prob.checkSubarraySum(new int%5B%5D%7B0%7D, 0)); // fals
 e%0A  

Update problem 523