leetcode_c++:图:Reconstruct Itinerary (332)
2016-08-28 15:16
525 查看
http://www.cnblogs.com/grandyang/p/5183210.html
class Solution { public: vector<string> findItinerary(vector<pair<string, string> > tickets) { vector<string> res; unordered_map<string, multiset<string> > m; for (auto a : tickets) { m[a.first].insert(a.second); } dfs(m, "JFK", res); return vector<string> (res.rbegin(), res.rend()); } void dfs(unordered_map<string, multiset<string> > &m, string s, vector<string> &res) { while (m[s].size()) { string t = *m[s].begin(); m[s].erase(m[s].begin()); dfs(m, t, res); } res.push_back(s); } };
相关文章推荐
- leetcode_c++:图:Minimum Height Trees(310)
- C/C++ 学习笔记:类相关
- C++STL的next_permutation
- leetcode_c++:图:Course Schedule II (207)
- leetcode_c++:图:Course Schedule(207)
- leetcode_c++:图:Clone Graph(133)
- C++数组初始化方法
- c++小数位 表示
- [C/C++笔面试]自己编程实现strcmp
- 迅雷2014C++研发笔试卷C解题分析
- C++智能指针详解(真的很经典 )
- Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(6)
- Visual Stdio C++ 编译器 编译 (GSL) GNU Scientific Library 的方法介绍(6)
- C++标准库之mutex
- 简单工厂 c++
- 求给定数等于最少的几个完全平方数之和
- Introduction to C++ Programming in UE4——UE4官方文档翻译与理解(二)
- c语言遍历某文件夹下的所有文件 包括子文件夹
- Canny边缘检测及C++实现
- 一天一天算日期~