If I am allowed to modify the triangle, I can do it in place, better than O(n).

below is my code.

```
public int minimumTotal(ArrayList<ArrayList<Integer>> triangle) {
int n = triangle.size();
if (n == 0){
return 0;
}
ArrayList<Integer> lastRow = triangle.get(0);//last row we proceed.
for(int rowNum = 2; rowNum <= n; rowNum++ ){//the row number;
ArrayList<Integer> row = triangle.get(rowNum-1);
for (int col = 1; col <= rowNum; col++){
int topLeft = col-1 >= 1 ? lastRow.get(col-2) : Integer.MAX_VALUE;
int top = col <= rowNum-1 ? lastRow.get(col-1) : Integer.MAX_VALUE;
int min = getMinOf(topLeft, top)+row.get(col-1);
row.set(col-1, min);
}
lastRow = row;
}
return minValueOf(triangle.get(n-1));
}
private int getMinOf(int value1, int value2){
return value1<value2 ? value1:value2;
}
private int minValueOf(ArrayList<Integer> list){
if (list.size() == 0){
return 0;
}
int min = list.get(0);
for(int v : list){
if (v < min){
min = v;
}
}
return min;
}
```