๋ฌธ์ ๐ฝ
https://school.programmers.co.kr/learn/courses/30/lessons/12913
๋ค๋ฅธ์ฌ๋ ํ์ด ๐ฝ
function solution(land) {
var answer = 0;
return Math.max(...land.reduce((a, c) => {
return [
c[0] + Math.max(a[1], a[2], a[3]),
c[1] + Math.max(a[0], a[2], a[3]),
c[2] + Math.max(a[0], a[1], a[3]),
c[3] + Math.max(a[0], a[1], a[2]),
];
}, [0, 0, 0, 0]));
}
๋ดํ์ด๐ฝ
1. ์ฑ๊ณต
function solution(land) {
var answer = []
for(let i=1; i<land.length; ++i){
land[i][0]+=Math.max(land[i-1][1],land[i-1][2],land[i-1][3])
land[i][1]+=Math.max(land[i-1][0],land[i-1][2],land[i-1][3])
land[i][2]+=Math.max(land[i-1][1],land[i-1][0],land[i-1][3])
land[i][3]+=Math.max(land[i-1][1],land[i-1][2],land[i-1][0])
}
return Math.max(...land[land.length-1])
}
๋๋์ ๐ฝ
๋์ ๊ณํ๋ฒ์ด๋ผ๋ ์๋ฃ๊ตฌ์กฐ๋ก ์ ๊ทผํด์ผ ํ๋ค~