思路:有向图的欧拉通路模板
class Solution {
public:
unordered_map<string, priority_queue<string, vector<string>, greater<string>>> ump;
vector<string> ans;
void dfs(string str) {
while (ump[str].size()) {
string tmp = ump[str].top();
ump[str].pop();
dfs(tmp);
}
ans.push_back(str);
}
vector<string> findItinerary(vector<vector<string>>& tickets) {
for (auto& each : tickets) {
ump[each[0]].push(each[1]);
}
dfs("JFK");
reverse(ans.begin(), ans.end());
return ans;
}
};