1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public int minimumTotal(List<List<Integer>> triangle) { int n = triangle.size(); int[][] dp = new int[n+1][n+1];
for (int i = n - 1; i >=0 ; i--) { for (int j = 0; j <= i; j++) { dp[i][j] = Math.min(dp[i+1][j], dp[i+1][j+1]) + triangle.get(i).get(j); } } return dp[0][0]; } }
|