[JavaScript]プログラマー整数三角形LEVEL 3


問題のソース
function solution(triangle) {
    var answer = 0;
    let dp = Array.from(Array(triangle.length), (v, i) => new Array(i+1).fill(0));
    dp[0][0] = triangle[0][0];
    
    for (let i=1; i<triangle.length; i++) {
        for (let j=0; j<triangle[i].length; j++) {
            const left = i-1 < 0 || j-1 < 0 ? 0 : dp[i-1][j-1];
            const right = i-1 < 0 ? 0 : dp[i-1][j];
            const max = left < right ? right : left;
            dp[i][j] = triangle[i][j] + max;
        }
    }
    
    return Math.max(...dp[dp.length-1]);
}