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闭包获取table中tr的索引 分类: JavaScript 2015-05-04 15:10 793人阅读 评论(0) 收藏

    使用javascript闭包获取table标签中tr的索引 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN& ...

  2. Android 开发工具类 31_WebService 获取手机号码归属地

    AndroidInteractWithWebService.xml <?xml version="1.0" encoding="utf-8"?> & ...

  3. ActiveMQ安全机制设置

    一.设置后台管理密码a.ActiveMQ使用的是jetty服务器,找到D:\div\apache-activemq-5.11.1\conf\jetty.xml文件: <bean id=" ...

  4. CentOS6的python2.6升级到python2.7以上版本(可能更详细)

    前言:一些第三方框架为了降低复杂性,新的版本已经开始不支持旧版本的python,比如Django这个web框架1.8版本及以上仅仅只支持python2.7及以上版本(记忆中是这个1.8版本) pip安 ...

  5. @Override 注解compiler1.5和compiler1.6不同

    说到注解问题,@interface 来定义注解类 这个注解出现是在jdk1.5版本出现. jdk1.5只支持@override对类的继承中方法重写的使用,不支持接口实现中方法重写的使用(这种情况下会报 ...

  6. Tensorflow 方法记录

    1.tf.convert_to_tensor:传入的list必须是一个有固定长度的list,如果为2维的list,第二维的list的长度必须是固定. 2.tf.layers.conv1d(),默认宽卷 ...

  7. 不开vip会员照样看vip电影(亲测有效)

    此为临时链接,仅用于文章预览,将在短期内失效关闭 不开vip会员照样看vip电影(亲测有效) 2018-03-08 mr_lee Python达人课堂 刚刚测试,真实有效,颇不接待要分享了... 土豪 ...

  8. Error : Weblogic Maven Plugin deployment WebLogic 12c

    Error : Weblogic Maven Plugin deployment i want to use weblogic-maven-plugin in my maven project in ...

  9. PowerDesigner中利用数据库表反向生成PDM(jdk必须是32位)

    第一步:创建一个空的PDM模型(选择对应的DBMS):File-->New 第二步:选择DataBase-->Configure Connections,配置即将连接的数据库 第三步:选择 ...

  10. 1000. A-B

    1000. A-B -----> http://soj.me/1000 Constraints Time Limit: 1 secs, Memory Limit: 32 MB Descripti ...