package leetcode;

/**
 * https://leetcode.com/problems/stone-game-vii/
 */
public class Problem1690 {
    public int stoneGameVII(int[] stones) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1690 prob = new Problem1690();
        System.out.println(prob.stoneGameVII(new int[]{5,3,1,4,2})); // 6
        System.out.println(prob.stoneGameVII(new int[]{7,90,5,1,100,10,10,2})); // 122
    }
}

@@ -152,32 +152,227 @@
     
-// TODO%0A        return 0
+int sum = 0;%0A        for (int stone : stones) %7B%0A            sum += stone;%0A        %7D%0A        Integer%5B%5D%5B%5D memo = new Integer%5Bstones.length%5D%5Bstones.length%5D;%0A        return stoneGame(stones, sum, 0, stones.length - 1, memo)
 ;%0A  
@@ -385,21 +385,22 @@
    p
-ublic
+rivate
  static 
 void
@@ -399,241 +399,589 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem1690 prob = new Problem1690();%0A        System.out.println(prob.stoneGameVII(new int%5B%5D%7B5,3,1,4,2%7D)); // 6%0A        System.out.println(prob.stoneGameVII(new int%5B%5D%7B7,90,5,1,100,10,10,2%7D)); // 122
+int stoneGame(int%5B%5D stones, int sum, int left, int right,%0A                                 Integer%5B%5D%5B%5D memo) %7B%0A        if (left == right) %7B%0A            return 0;%0A        %7D%0A        if (memo%5Bleft%5D%5Bright%5D != null) %7B%0A            return memo%5Bleft%5D%5Bright%5D;%0A        %7D%0A        int leftSum = sum - stones%5Bleft%5D;%0A        int a =  leftSum - stoneGame(stones, leftSum, left + 1, right, memo);%0A        int rightSum = sum - stones%5Bright%5D;%0A        int b = rightSum - stoneGame(stones, rightSum, left, right - 1, memo);%0A        memo%5Bleft%5D%5Bright%5D = Math.max(a, b);%0A        return memo%5Bleft%5D%5Bright%5D;
 %0A   

Solve problem 1690