package leetcode;

/**
 * https://leetcode.com/problems/minimum-ascii-delete-sum-for-two-strings/
 */
public class Problem712 {
    public int minimumDeleteSum(String s1, String s2) {
        // TODO
        return minimumDeleteSum(s1, s2, s1.length(), s2.length());
    }

    private static int minimumDeleteSum(String s1, String s2, int i, int j) {
        if (i == 0) {
            return j;
        }
        if (j == 0) {
            return i;
        }
        if (s1.charAt(i - 1) == s2.charAt(j - 1)) {
            return minimumDeleteSum(s1, s2, i - 1, j - 1);
        }
        int ival = 0;
        if (i < s1.length()) {
            ival = s1.charAt(i);
        }
        int jval = 0;
        if (j < s2.length()) {
            jval = s2.charAt(j);
        }
        int a = minimumDeleteSum(s1, s2, i, j - 1);
        int b = minimumDeleteSum(s1, s2, i - 1, j);
        int min = 1 + Math.min(a, b);
        return min;
    }

    public static void main(String[] args) {
        Problem712 prob = new Problem712();
        System.out.println(prob.minimumDeleteSum("sea", "eat")); // 231
        System.out.println(prob.minimumDeleteSum("delete", "leet")); // 403
    }
}

@@ -386,17 +386,33 @@
  return 
-j
+Integer.MAX_VALUE
 ;%0A      
@@ -456,17 +456,33 @@
  return 
-i
+Integer.MAX_VALUE
 ;%0A      
@@ -863,72 +863,288 @@
    i
-nt b = minimumDeleteSum(s1, s2, i - 1, j);%0A        int min = 1 +
+f (a == Integer.MAX_VALUE) %7B%0A            a = jval;%0A        %7D else %7B%0A            a += jval;%0A        %7D%0A        int b = minimumDeleteSum(s1, s2, i - 1, j);%0A        if (b == Integer.MAX_VALUE) %7B%0A            b = ival;%0A        %7D else %7B%0A            b += ival;%0A        %7D%0A        int min =
  Mat

Update problem 712