332. Reconstruct Itinerary Hard
1/**
2 * [332] Reconstruct Itinerary
3 *
4 * You are given a list of airline tickets where tickets[i] = [fromi, toi] represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it.
5 * All of the tickets belong to a man who departs from "JFK", thus, the itinerary must begin with "JFK". If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string.
6 *
7 * For example, the itinerary ["JFK", "LGA"] has a smaller lexical order than ["JFK", "LGB"].
8 *
9 * You may assume all tickets form at least one valid itinerary. You must use all the tickets once and only once.
10 *
11 * Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/itinerary1-graph.jpg" style="width: 382px; height: 222px;" />
13 * Input: tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]]
14 * Output: ["JFK","MUC","LHR","SFO","SJC"]
15 *
16 * Example 2:
17 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/14/itinerary2-graph.jpg" style="width: 222px; height: 230px;" />
18 * Input: tickets = [["JFK","SFO"],["JFK","ATL"],["SFO","ATL"],["ATL","JFK"],["ATL","SFO"]]
19 * Output: ["JFK","ATL","JFK","SFO","ATL","SFO"]
20 * Explanation: Another possible reconstruction is ["JFK","SFO","ATL","JFK","ATL","SFO"] but it is larger in lexical order.
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= tickets.length <= 300
26 * tickets[i].length == 2
27 * fromi.length == 3
28 * toi.length == 3
29 * fromi and toi consist of uppercase English letters.
30 * fromi != toi
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/reconstruct-itinerary/
36// discuss: https://leetcode.com/problems/reconstruct-itinerary/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn find_itinerary(tickets: Vec<Vec<String>>) -> Vec<String> {
42 vec![]
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_332() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.