- 三角形最小路径和
function minimumTotal(triangle: number[][]): number {
const len = triangle.length
if (len === 1) return triangle[0][0]
let arr: number[][] = new Array()
triangle.forEach(e => {
arr.push(new Array(e.length))
})
arr[0][0] = triangle[0][0]
let min = Infinity
for (let i1 = 1; i1 < arr.length; i1++) {
for (let i2 = 0; i2 < arr[i1].length; i2++) {
if (i2 === 0) {
arr[i1][i2] = triangle[i1][i2] + arr[i1 - 1][i2]
} else if (i2 === i1) {
arr[i1][i2] = triangle[i1][i2] + arr[i1 - 1][i2 - 1]
} else {
arr[i1][i2] = triangle[i1][i2] + Math.min(arr[i1 - 1][i2 - 1], arr[i1 - 1][i2])
}
if (i1 === len - 1) {
min = Math.min(min, arr[i1][i2])
}
}
}
return min
};