Leetcode 599 Minimum Index Sum of Two Lists
来源:互联网 发布:合肥数码美工招聘信息 编辑:程序博客网 时间:2024/06/05 07:46
Leetcode 599 Minimum Index Sum of Two Lists
class Solution {public: vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) { unordered_map<string,int> nameAndOrder;//list1中的字符串与其对应的下标值 for(int i = 0;i < list1.size();i ++) { nameAndOrder[list1[i]] = i; } unordered_map<int,vector<string>> result;//ATTENTION 相同下标和的字符串可能会有多个,所以对应的是vector<string>,应该也可以只用一个vector int minIndexSum = list1.size() + list2.size(); for(int j = 0;j < list2.size();j ++) { auto commonName = nameAndOrder.find(list2[j]);//在list1中寻找相同的字符串commonName,commonName->second是其在list1中的下标值 if(commonName != nameAndOrder.end()) { int indexSum = commonName->second + j;//indexNum是这个字符串在两个list中的下标值之和 if(indexSum <= minIndexSum)//=等于号必须要有,结果可能是多个 { minIndexSum = indexSum; result[minIndexSum].push_back(list2[j]); } } } return result[minIndexSum];//是一个vector }};
阅读全文
0 0
- LeetCode 599 Minimum Index Sum of Two Lists
- Leetcode 599 Minimum Index Sum of Two Lists
- 599Minimum Index Sum of Two Lists
- [leetcode] 599. Minimum Index Sum of Two Lists
- leetcode 599. Minimum Index Sum of Two Lists
- LeetCode 599. Minimum Index Sum of Two Lists(map,unordered_map)
- LeetCode-599. Minimum Index Sum of Two Lists
- Leetcode-599.Minimum Index Sum of Two Lists
- leetcode 599. Minimum Index Sum of Two Lists
- [LeetCode]599. Minimum Index Sum of Two Lists
- LeetCode 599. Minimum Index Sum of Two Lists
- 【LeetCode】599. Minimum Index Sum of Two Lists
- leetcode 599. Minimum Index Sum of Two Lists
- 599. Minimum Index Sum of Two Lists
- 599. Minimum Index Sum of Two Lists
- 599. Minimum Index Sum of Two Lists
- 599. Minimum Index Sum of Two Lists
- 599. Minimum Index Sum of Two Lists
- Leetcode 453 Minimum Moves to Equal Array Elements
- 如何定义java中的方法
- SQL Server远程定时备份数据库脚本
- LNMP 性能优化之 PHP 性能优化
- Leetcode 462 Minimum Moves to Equal Array Elements II
- Leetcode 599 Minimum Index Sum of Two Lists
- idea 2017打包jar包
- Jdk中的Timer
- hdu 6036 NTT取模(板子)+组合数学
- Leetcode 643 Maximum Average Subarray I
- 【Java虚拟机】之五 语法糖的味道
- Java中无参带返回值方法的使用
- 如何才能变得富有?秘密就在这三点里
- Leetcode 661 Image Smoother