프로그래머스 #10
DFS / BFS - 여행경로
function solution(tickets) {
const list = {};
const path = ["ICN"];
tickets.sort();
for (let [from, to] of tickets){
if(!list[from]) list[from] = [to];
else list[from].push(to);
}
// for (let from in list){
// if(list[from].length !== 1) list[from].sort();
// }
const queue = [];
const enqueue = (el) => queue.push(el);
const dequeue = () => queue.shift();
enqueue(list["ICN"].shift());
while(queue.length > 0){
const from = dequeue();
path.push(from);
if(!list[from] || list[from].length === 0) break;
enqueue(list[from].shift());
}
return path;
}
통과안된 케이스의 입력값을 모르니 정확히 어떻게 틀렸는지 아직 감이 오지 않는다
아마 정렬 순서가 잘못됬지 싶다
테스트 케이스가 더 필요할 것 같다
또는 DFS로 풀어봐야지
Author And Source
이 문제에 관하여(프로그래머스 #10), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@ntk100/프로그래머스-10저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)