Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

땅따먹기 #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

땅따먹기 #142

wants to merge 1 commit into from

Conversation

say-young516
Copy link
Contributor

🔗 Related Issues

🔍 문제

프로그래머스 - 땅따먹기

✅ 풀이 방법

추후 첨부

📜 최종 소스코드

function solution(land) {
    const arr=Array.from(Array(land.length),()=>Array(4).fill(0));
    arr[0][0]=land[0][0];
    arr[0][1]=land[0][1];
    arr[0][2]=land[0][2];
    arr[0][3]=land[0][3];
    for(let i=1;i<land.length;i++){
         arr[i][0]=land[i][0]+Math.max(arr[i-1][1],arr[i-1][2],arr[i-1][3]);
         arr[i][1]=land[i][1]+Math.max(arr[i-1][0],arr[i-1][2],arr[i-1][3]);
         arr[i][2]=land[i][2]+Math.max(arr[i-1][0],arr[i-1][1],arr[i-1][3]);
         arr[i][3]=land[i][3]+Math.max(arr[i-1][0],arr[i-1][1],arr[i-1][2]);
    }
    arr.map(v=>v.sort((a,b)=>a-b));
    return arr[land.length-1][3];
}

@say-young516 say-young516 self-assigned this Mar 4, 2023
@say-young516 say-young516 changed the title 최종코드 땅따먹기 Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

땅따먹기
1 participant