nikunjsoni

332

Jun 25th, 2021
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     unordered_map<string, multiset<string>> targets;
  4.     vector<string> route;
  5.     vector<string> findItinerary(vector<vector<string>> tickets) {
  6.         for(auto ticket : tickets)
  7.             targets[ticket[0]].insert(ticket[1]);
  8.         visit("JFK");
  9.         return vector<string>(route.rbegin(), route.rend());
  10.     }
  11.  
  12.     void visit(string airport) {
  13.         while(targets[airport].size()) {
  14.             string next = *targets[airport].begin();
  15.             targets[airport].erase(targets[airport].begin());
  16.             visit(next);
  17.         }
  18.         route.push_back(airport);
  19.     }
  20. };
RAW Paste Data