public int minimumTotal(List<List<Integer>> triangle) {
        if(triangle==null || triangle.isEmpty()){
            return 0;
        }
        int maxLength = triangle.get(triangle.size()-1).size();
        int[][] f = new int[triangle.size()][maxLength];
        f[0][0]=triangle.get(0).get(0);
        for(int i=1; i<triangle.size(); i++){
            for(int j=0; j<i+1; j++){
                int left = j-1<0?0:j-1;
                int right = j>i-1?i-1:j;
                f[i][j]=Math.min(f[i-1][left], f[i-1][right])+triangle.get(i).get(j);
            }
        }
        int min = f[triangle.size()-1][0];
        for(int i=1; i<triangle.get(triangle.size()-1).size(); i++){
            if(f[triangle.size()-1][i]<min){
                min = f[triangle.size()-1][i];
            }
        }
        return min;
    }