Title: #332 - Reconstruct Itinerary - LeetCode JavaScript Solutions
Open Graph Title: #332 - Reconstruct Itinerary - LeetCode JavaScript Solutions
X Title: #332 - Reconstruct Itinerary - LeetCode JavaScript Solutions
Description: You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reco...
Open Graph Description: You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reco...
X Description: You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reco...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/reconstruct-itinerary
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/reconstruct-itinerary","name":"#332 - Reconstruct Itinerary - LeetCode JavaScript Solutions","description":"You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reco...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string[][]} tickets\n * @return {string[]}\n */\nvar findItinerary = function(tickets) {\n const graph = new Map();\n const itinerary = [];\n\n for (const [from, to] of tickets) {\n if (!graph.has(from)) {\n graph.set(from, []);\n }\n graph.get(from).push(to);\n }\n\n for (const [_, destinations] of graph) {\n destinations.sort().reverse();\n }\n\n dfs('JFK');\n\n return itinerary.reverse();\n\n function dfs(airport) {\n while (graph.has(airport) && graph.get(airport).length) {\n dfs(graph.get(airport).pop());\n }\n itinerary.push(airport);\n }\n};","keywords":"LeetCode 332, #332 - Reconstruct Itinerary, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/reconstruct-itinerary |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/reconstruct-itinerary/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0332-reconstruct-itinerary.js |
| Depth-First Search | https://leetcodejavascript.com/tags/depth-first-search |
| Graph | https://leetcodejavascript.com/tags/graph |
| Eulerian Circuit | https://leetcodejavascript.com/tags/eulerian-circuit |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width,initial-scale=1
Robots: index, follow