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> triangle
) {
int row = triangle.size();
Listres = new LinkedList<>(triangle.get(row - 1));
for (int i = row - 2; i >= 0; i--) {
ListcurrentRow = 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:填充每个节点的下一个右侧节点指针
LeetCode刷题实战117:填充每个节点的下一个右侧节点指针 II
评论