-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolutioin120.java
More file actions
25 lines (24 loc) · 793 Bytes
/
Solutioin120.java
File metadata and controls
25 lines (24 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import java.util.List;
/**
* Created by Alex on 2016/2/29.
*/
public class Solutioin120 {
public int minimumTotal(List<List<Integer>> triangle) {
for(int i = triangle.size()-1; i >= 0; i--){
for(int j = 0; j < triangle.get(i).size(); j++){
if(i != triangle.size()-1){
int number = triangle.get(i).get(j);
int left = triangle.get(i+1).get(j);
int right = triangle.get(i+1).get(j+1);
if(left > right){
number += right;
}else{
number += left;
}
triangle.get(i).set(j,number);
}
}
}
return triangle.get(0).get(0);
}
}