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

[Lv.3] 여행경로 #157

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

[Lv.3] 여행경로 #157

wants to merge 1 commit into from

Conversation

say-young516
Copy link
Contributor

🔗 Related Issues

🔍 문제

프로그래머스 - 여행경로

✅ 풀이 방법

추후 첨부

📜 최종 소스코드

function solution(tickets) {
    const answer = [];
    tickets.sort();
    const visited=new Array(tickets.length).fill(false);
    function dfs(cnt){
        if(cnt===tickets.length) return;
        for(let i=0;i<tickets.length;i++){
            if(visited[i]) continue;
            if(tickets[i][0]===answer[answer.length-1]){
                visited[i]=true;
                answer.push(tickets[i][1]);
                dfs(cnt+1);
                visited[i]=false;
            }
            if(answer.length===tickets.length+1) return answer;
        }
      
     if(visited.filter((v)=>v===false).length!==0){
        answer.pop();
        return;
     }
    }
    answer.push("ICN");
    dfs(0);
    return answer;
}

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