👍 2022년 2월 4일
<script>
function solution(land) {
let answer = 0;
let acc;
let newAcc = [0,0,0,0];
land.forEach((v,i) => {
if (i === 0) acc = v;
else {
let maxIdx = acc.indexOf(Math.max(...acc));
for (let idx=0; idx<v.length; idx++) {
if (maxIdx !== idx) {
newAcc[idx] = (v[idx] + Math.max(...acc));
} else {
let accCopy = [...acc];
accCopy[maxIdx] = 0;
newAcc[idx] = (v[idx] + Math.max(...accCopy));
}
}
acc = [...newAcc];
}
})
answer = Math.max(...acc);
return answer;
}
</script>