Problem Description
[https://leetcode.com/problems/triangle/]
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
思路
DP
hahaha,我的DP越来越熟练了!!!
Code
package q120;
import java.util.List;
public class Solution {
public int minimumTotal(List<List<Integer>> triangle) {
int m = triangle.size();
int tmp;
for (int i = m - 2; i >= 0; i--) {
for (int j = 0; j <= i; j++) {
tmp = triangle.get(i).get(j)
+ Math.min(triangle.get(i + 1).get(j),
triangle.get(i + 1).get(j + 1));
triangle.get(i).set(j, tmp);
}
}
return triangle.get(0).get(0);
}
}