1、题目描述

2.问题分析

直接是用hash table 解决问题

3、代码

 vector<string> findRestaurant(vector<string>& list1, vector<string>& list2) {

         vector<string> result;
map<string,int>m;
for(int i = ; i < list1.size() ; i++ )
{
m.insert( std::pair<string,int>( list1[i],i) ) ;
} map<string,int>m2 ;
for(int i = ; i < list2.size() ; i++ )
{
m2.insert( std::pair<string,int>(list2[i],i) );
} int min_index = list1.size() + list2.size() ; for( map<string,int>::iterator it = m.begin() ; it != m.end() ; it++ )
{
auto it_find = m2.find( it->first );
if( it_find != m2.end() )
{
int index_sum = it->second + it_find->second;
if( index_sum < min_index )
{
result.clear();
result.push_back( it->first) ;
min_index = index_sum;
}else if( index_sum == min_index )
{
result.push_back( it->first ) ;
} }
} return result; }

LeetCode 题解之Minimum Index Sum of Two Lists的更多相关文章

  1. 【LeetCode】599. Minimum Index Sum of Two Lists 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 方法一:找到公共元素再求索引和 方法二:索引求和,使 ...

  2. LeetCode算法题-Minimum Index Sum of Two Lists(Java实现)

    这是悦乐书的第272次更新,第286篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第139题(顺位题号是599).假设Andy和Doris想要选择一家餐馆吃晚餐,他们都有 ...

  3. 【Leetcode_easy】599. Minimum Index Sum of Two Lists

    problem 599. Minimum Index Sum of Two Lists 题意:给出两个字符串数组,找到坐标位置之和最小的相同的字符串. 计算两个的坐标之和,如果与最小坐标和sum相同, ...

  4. LeetCode Minimum Index Sum of Two Lists

    原题链接在这里:https://leetcode.com/problems/minimum-index-sum-of-two-lists/description/ 题目: Suppose Andy a ...

  5. LeetCode 599. Minimum Index Sum of Two Lists (从两个lists里找到相同的并且位置总和最靠前的)

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...

  6. [LeetCode] Minimum Index Sum of Two Lists 两个表单的最小坐标和

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...

  7. LeetCode 599: 两个列表的最小索引总和 Minimum Index Sum of Two Lists

    题目: 假设 Andy 和 Doris 想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. Suppose Andy and Doris want to cho ...

  8. [LeetCode&Python] Problem 599. Minimum Index Sum of Two Lists

    Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite ...

  9. C#LeetCode刷题之#599-两个列表的最小索引总和​​​​​​​​​​​​​​(Minimum Index Sum of Two Lists)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3802 访问. 假设Andy和Doris想在晚餐时选择一家餐厅,并 ...

随机推荐

  1. Javascript中Date对象的格式化

    很多语言中都带有日期的格式化函数,而Javascript中却没有提供类似的方法.之前从某位前人的帖子中发现了下面的代码,感觉非常简洁,存留备用. /** * 时间对象的格式化; */ Date.pro ...

  2. free -m内存使用详解

    第一部分Mem这行:total -> 内存总数: 32014M=32Gused -> 已经使用的内存数: 7665Mfree -> 空闲的内存数: 24349Mshared -> ...

  3. CRF两个例子的理解

    概率计算例子: 预测例子:

  4. jvm间歇性崩溃分析

    http://www.cnblogs.com/LBSer/p/4417148.html 1 问题描述 某服务有两台机器,每隔几天会报警load高,一开始看监控发现gc时间抖动很大,以为是发生了full ...

  5. Git 什么时候用什么指令

    转自:http://blog.gogojimmy.net/2012/02/29/git-scenario/ Git 教學(1):Git的基本使用 Git 教學(2):Git Branch 的操作與基本 ...

  6. IOS bug之cannot be opened because the project file cannot be parsed

    刚才用Cornerstone更新代码后,再次打开项目时,不能打开,提示cannot be opened because the project file cannot be parsed后来在网上查了 ...

  7. [转]ORA-28001: the password has expired解决方法

    本文转自:http://blog.csdn.net/btt2013/article/details/54862420 参考文献:http://www.zhetao.com/content259 后台报 ...

  8. BG.Hive - part1

    1. Hive架构 What is hive? Facebook,https://en.wikipedia.org/wiki/Apache_Hive a> 一种工具,可以通过SQL轻松的访问数据 ...

  9. Python第三方库____jieba

    jieba是优秀的中文分词第三方库 中文文本需要通过分词获得单个词语 jieba是优秀的中文分词第三方库,需要额外安装  (pip install jieba) jieba库提供三种分词模式,最简单只 ...

  10. Walkway.js – 创建简约的 SVG 线条动画

    Walkway.js 是一个使用线条和路径元素组成 SVG 动画图像的简单方法.只需根据提供的配置对象创建一个新的 Walkway 实例就可以了.这种效果特别适合那些崇尚简约设计风格的网页.目前, W ...