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);
}
};

332. Reconstruct Itinerary的更多相关文章

  1. 【LeetCode】332. Reconstruct Itinerary

    题目: Given a list of airline tickets represented by pairs of departure and arrival airports [from, to ...

  2. [leetcode]332. Reconstruct Itinerary

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...

  3. 332 Reconstruct Itinerary 重建行程单

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...

  4. 【LeetCode】332. Reconstruct Itinerary 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 后序遍历 相似题目 参考资料 日期 题目地址:htt ...

  5. 332. Reconstruct Itinerary (leetcode)

    1. build the graph and then dfs -- graph <String, List<String>>,  (the value is sorted a ...

  6. 【LeetCode】Reconstruct Itinerary(332)

    1. Description Given a list of airline tickets represented by pairs of departure and arrival airport ...

  7. [LeetCode] Reconstruct Itinerary 重建行程单

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...

  8. Reconstruct Itinerary

    Given a list of airline tickets represented by pairs of departure and arrival airports [from, to], r ...

  9. LeetCode Reconstruct Itinerary

    原题链接在这里:https://leetcode.com/problems/reconstruct-itinerary/ 题目: Given a list of airline tickets rep ...

随机推荐

  1. svn图标显示不正常,文件夹显示但文件不显示svn图标

    svn图标显示不正常,文件夹显示但文件不显示svn图标   这个问题的引发是自己造成的,使用myEclipse时progress会卡在 refresh svn status cache (0%)这里, ...

  2. [工作积累点滴整理]虚拟化、云计算配置规划<一>

    目 录1. 服务器虚拟化的相关配置建议 11.1. 服务器的基本配置建议 11.1.1. CPU配置 11.1.2. 服务器内存配置 21.1.3. 物理网卡配置 21.1.4. 服务器磁盘配置 21 ...

  3. 两种计算Java对象大小的方法

    之前想研究一下unsafe类,碰巧在网上看到了这篇文章,觉得写得很好,就转载过来.原文出处是: http://blog.csdn.net/iter_zc/article/details/4182271 ...

  4. 长大Tips的第一步

    任务进度:登陆界面的初步设计. 运行环境:windows10 编译环境:netbeans 编写语言:java 界面展示: 任务简介: 本次任务指示简单的完成了界面设计,登陆按钮暂未实现,持续更新中,敬 ...

  5. 在VMware上安装ubuntu——网络类型

    安装虚拟机时,向导提示选择网络类型: 当使用仅主机模式网络时,虚拟机和物理机不能互相访问共享.

  6. JVM原理:4 运行期优化

    JVM运行期优化 Java程序在运行的期间,可能会有某个方法或者代码块的运行特别频繁时,就会把这些代码认定为“热点代码”.为了提高热点代码的执行效率,在运行时JVM会将这些代码编译成与本地平台相关的机 ...

  7. bzoj1965 [Ahoi2005]洗牌

    Description 为了表彰小联为Samuel星球的探险所做出的贡献,小联被邀请参加Samuel星球近距离载人探险活动. 由于Samuel星球相当遥远,科学家们要在飞船中度过相当长的一段时间,小联 ...

  8. 特殊权限的介绍 SGID SUID SBIT

    Set UID 当s这个标志出现在文件所有者的x权限上时,如/usr/bin/passwd这个文件的权限状态:“-rwsr-xr-x.”,此时就被称为Set UID,简称为SUID.那么这个特殊权限的 ...

  9. iOS 适配安装包

    每次自己需求都是去一顿搜索,所以就在此记录一下,免得以后再麻烦. 链接: https://pan.baidu.com/s/1zXEFlt94bz3O1e3GdtG92w 密码: rc4k 摘抄自:ht ...

  10. 【iOS】那些年,遇到的小坑

    'NSInvalidArgumentException', reason: '-[__NSPlaceholderDictionary initWithObjectsAndKeys:]: second ...