题目
法1:DP
class Solution {public int minimumTotal(List<List<Integer>> triangle) {int n = triangle.size();if (n == 1) {return triangle.get(0).get(0);}int[] tmp = new int[n];tmp[0] = triangle.get(0).get(0);int ans = Integer.MAX_VALUE;for (int i = 1; i < n; ++i) {for (int j = i; j >= 0; --j) {if (j == i) {tmp[j] = tmp[j - 1] + triangle.get(i).get(j);} else if (j < i && j > 0) {tmp[j] = Math.min(tmp[j], tmp[j - 1]) + triangle.get(i).get(j);} else if (j == 0) {tmp[j] = tmp[j] + triangle.get(i).get(j);}if (i == n - 1) {ans = Math.min(ans, tmp[j]);}}}return ans;}
}