[LeetCode] 1466. Reorder Routes to Make All Paths Lead to the City Zero, Medium
·
CodingTest/LeetCode
1. 문제도시의 수 n이 주어지고, 도시 간의 연결 도로 정보 2차원 배열이 주어질 때 모든 도시에서 0번 도시로 갈 수 있도록 변경해야하는 도로의 수를 반환하라.2. 해결function minReorder(n: number, connections: number[][]): number { const visited = new Array(n).fill(false); const map = new Map(); let count = 0; for (const [from, to] of connections) { map.set(from, (map.get(from) || []).concat([[to, 1]])); map.set(to, (map.get(to) || []).c..