✨ 정답 ✨
let answer = [];
function solution(tickets) {
let ticketsSort = tickets.sort();
return DFS("ICN", ticketsSort, ["ICN"]);
}
const DFS=(ticket, ticketsSort, planArr)=>{
if(ticketsSort.length == 0) {
answer = planArr;
return answer;
}
for(let i=0; i<ticketsSort.length; i++){
if(ticketsSort[i][0] == ticket && answer.length == 0) {
let reTickets = [...ticketsSort.slice(0, i), ...ticketsSort.slice(i+1)];
if( i == ticketsSort.length-1){
return DFS(ticketsSort[i][1], reTickets, [...planArr, ticketsSort[i][1]]);
}else {
DFS(ticketsSort[i][1], reTickets, [...planArr, ticketsSort[i][1]]);
}
}
}
return answer;
}
🧵 참고한 정답지 🧵
https://cocococo.tistory.com/entry/%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%A8%B8%EC%8A%A4JavaScript-Lv3-%EC%97%AC%ED%96%89%EA%B2%BD%EB%A1%9C
💡💡 기억해야 할 점 💡💡