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. Java—关于String的分析

    一.两种赋值方式的比较 1.直接赋值法:String s1="abc"; 这种赋值方法用的最多,因为它可能不需要创建对象,或者只创建一次. 它首先会判断字符串常量池有没有存在字符串 ...

  2. Django中涉及金融的项目

    在Django中,如果一个项目涉及了金融,他的要求是十分严格的. 所以嘞,这里就有一些坑,很多坑,第一次开发的时候很容易出现一系列的错误 在涉及金融计算的地方,不能使用float类型 什么鬼,但事实就 ...

  3. Vue的watch监听事件

    Vue的watch监听事件 相关Html: <!DOCTYPE html> <html lang="en"> <head> <meta c ...

  4. 【链表】Rotate List(三个指针)

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  5. SPSS学习系列之SPSS Modeler (简称SPSS)是什么?

    不多说,直接上干货! 推荐博客 SPSS学习系列之SPSS Statistics(简称SPSS)是什么? 官方简介: SPSS Modeler 是全球领先的数据挖掘.预测分析平台软件,拥有简单的图形界 ...

  6. 如何虚拟机里安装Win8操作系统

    不多说,直接上干货! Windows Server 2003.2008.2012系统的安装 推荐网址:打开MSDN网站(http://msdn.itellyou.cn ) 关于给电脑换系统,很多人会花 ...

  7. Nginx的几个常用配置和技巧

    文章列举了几个Nginx常见的,实用的,有趣的配置,希望看过之后能说一句:学到了! 一个站点配置多个域名 server { listen 80; server_name ops-coffee.cn b ...

  8. js便签笔记(1)——说说HTMLCollection、NodeList以及NamedNodeMap

    介绍 在js的dom操作中,除了常用的document.html**Element之外,还有三个集合对象,即HTMLCollection.NodeList以及NamedNodeMap.试看以下操作: ...

  9. MCS锁和CLH锁

    CLH锁:自旋锁,在上一个节点上等待,先上代码: public class CLHLock { /** * 保证原子性操作 * */ private AtomicReference<Node&g ...

  10. Python---战机小游戏,学习pygame

    import pygame # 导入游戏包 pygame.init() # 导入并初始化所有pygame模块,使用其他模块之前必须先调用init()方法 print('下面是游戏代码:') # 绘制矩 ...