zoukankan      html  css  js  c++  java
  • 332. Reconstruct Itinerary

    class Solution {
    public:
        vector<string> path;
        unordered_map<string, multiset<string>> m;
        vector<string> findItinerary(vector<pair<string, string>> tickets) {
            for (auto &p : tickets)
                m[p.first].insert(p.second);
            dfs("JFK");
            reverse(path.begin(), path.end());
            return path;
        }
        void dfs(const string cur) {
            while (!m[cur].empty()) {
                auto peer = m[cur].begin();
                string next = *peer;
                m[cur].erase(peer);
                dfs(next);
            }
            path.push_back(cur);
        }
    };
  • 相关阅读:
    十一作业
    11.20
    11.13 第十二次、
    11.13 第十一次、
    11.06第十次、
    11.06第九次、
    10.30
    10.23
    10.16
    10.9
  • 原文地址:https://www.cnblogs.com/JTechRoad/p/10052139.html
Copyright © 2011-2022 走看看