中级农民
- 积分
- 104
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2015-3-7
- 最后登录
- 1970-1-1
|
注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号
x
https://leetcode.com/problems/triangle/
class Solution{
public int minimumTotal(List<List<Integer>> triangle) {
int[] A = new int[triangle.size()+1];
int res = Integer.MAX_VALUE;
A[0] = triangle.get(0).get(0);
for(int i = 1; i < triangle.size(); i++){
for(int j = i; j >= 0;j--){
if(j == 0){
A[j] = A[j] + triangle.get(i).get(j);
}else{
A[j] = Math.min(A[j], A[j - 1]) + triangle.get(i).get(j);
}
if(i == triangle.size() - 1)
res = Math.min(A[j], res);
}
}
return res;
}
}
Wrong Answer
Details
Input
[[2],[3,4],[6,5,7],[4,1,8,3]]
Output
3
Expected
11
|
上一篇: 大佬们求点刷题的套路下一篇: 求救897. Increasing Order Search Tree,想了一晚上也没看懂的答案
|