-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path332.cpp
More file actions
27 lines (25 loc) · 676 Bytes
/
332.cpp
File metadata and controls
27 lines (25 loc) · 676 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Solution {
public:
unordered_map<string,multiset<string>> graph;
vector<string> res;
void dfs(string s){
if(graph.count(s)){
while(!graph[s].empty()){
string dst = *graph[s].begin();
graph[s].erase(graph[s].begin());
dfs(dst);
}
}
res.push_back(s);
}
vector<string> findItinerary(vector<vector<string>>& tickets) {
for(auto ticket: tickets){
auto u = ticket[0];
auto v = ticket[1];
graph[u].insert(v);
}
dfs("JFK");
reverse(res.begin(),res.end());
return res;
}
};