땅따먹기

function solution(land) {
  for (let i = land.length - 2; i >= 0; i--) {
    const currentLine = land[i];
    const nextLine = land[i + 1];
    currentLine.forEach((num, idx) => {
      let max = 0;
      for (let j = 0; j < nextLine.length; j++) {
        if (j == idx) continue;
        if (nextLine[j] > max) {
          max = nextLine[j];
        }
      }
      land[i][idx] += max;
    });
  }
  return Math.max(...land[0]);
}
  • 동적 프로그래밍 너무 어렵다...

0개의 댓글