My JAVA DP clean solution


  • 0
    Z
        public int getMoneyAmount(int n) {
            int[][] A = new int[n+2][n+2];
            for(int len = 2;len <=n;len++){
                for(int i=1;i<=n-len+1;i++) {
                    A[i][i+len-1] = Integer.MAX_VALUE;
                    for(int j=i;j<i+len;j++) {
                        A[i][i+len-1] = Math.min(A[i][i+len-1],j + Math.max(A[i][j-1],A[j+1][i+len-1]));
                    }
                }
            }
            return A[1][n] ;
        }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.