LeetCode刷题实战120: 三角形最小路径和
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.
题意
解题
class Solution {
public int minimumTotal(List<List<Integer>> triangle) {
int row = triangle.size();
List<Integer> res = new LinkedList<>(triangle.get(row - 1));
for (int i = row - 2; i >= 0; i--) {
List<Integer> currentRow = triangle.get(i);
for (int j = 0; j < currentRow.size(); j++) {
res.set(j, Math.min(res.get(j), res.get(j + 1)) + currentRow.get(j));
}
}
return res.get(0);
}
}
LeetCode刷题实战116:填充每个节点的下一个右侧节点指针
赞 (0)