public class Solution {
public string[] FindRestaurant(string[] list1, string[] list2) {
var dic = new Dictionary<string, int>();
for (int i = ; i < list1.Length; i++)
{
for (int j = ; j < list2.Length; j++)
{
if (list1[i] == list2[j])
{
var restaurant = list1[i];
var index = i + j;
if (!dic.ContainsKey(restaurant))
{
dic.Add(restaurant, index);
}
}
}
} var minIndex = dic.Min(x => x.Value);
var list = dic.Where(x => x.Value == minIndex).Select(x => x.Key).ToList();
return list.ToArray();
}
}

https://leetcode.com/problems/minimum-index-sum-of-two-lists/#/description

leetcode599的更多相关文章

  1. [Swift]LeetCode599. 两个列表的最小索引总和 | 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 ...

  2. Leetcode599.Minimum Index Sum of Two Lists

    假设Andy和Doris想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. 你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅. 如果答案不止一个,则输出所有答 ...

随机推荐

  1. ActionDescriptor 的认识

    ActionDescriptor的作用是对Action方法的元数据的描述,通过ActionDescriptor我们可以获取到action方法的相关的名称,所属控制器,方法的参数列表,应用到方法上的特性 ...

  2. jQuery中this与$(this)的区别

    起初以为this和$(this)就是一模子刻出来.但是我在阅读时,和coding时发现,总不是一回事,这里就谈谈this与$(this)的区别. jQuery中this与$(this)的区别 $(&q ...

  3. css3 hover 的一些小效果

    Hover 2D Transforms Grow Shrink Pulse Pulse-grow Pulse-shrink Push Top Rotate Grow-rotate Float Sink ...

  4. C++静态数据成员实现

    静态数据成员是在一个类中用关键字static声明的数据成员.在C++中,一般使用静态成员来代替C语言的全局变量,以达到数据共享.C和C++的全局变量有一定的局限性,可以任意被修改,也容易和其它的变量名 ...

  5. EMQ (Erlang/Enterprise/Elastic MQTT Broker)

    EMQ (Erlang/Enterprise/Elastic MQTT Broker) https://www.cnblogs.com/SteveLee/p/9843215.html MQ介绍 EMQ ...

  6. JDBC 3 通过PreparedStatement 对数据库进行增删改查

    下面程序沿用上面的封装. 1 插入数据 public boolean ChaRu3(User user){ boolean flag=true; Connection conn=null; Prepa ...

  7. 剑指offer-第三章高质量代码(树的子结构)

    题目:输入两个二叉树A和B,判断B是不是A的子结构. 思路:遍历A树找到B树的根节点,然后再判断左右子树是否相同.不相同再往下找.重复改过程. 子结构的描述如下图所示: C++代码: #include ...

  8. DbEntry 简单实现

    在着手编码之前首先安装DbEntry DbEntry.Net.4.1.Setup.zip 在建立类库时选择 DbEntryClassLibrary 如图 DbEntryClassLibrary1 中建 ...

  9. java多线程:synchronized和lock比较浅析

    转载:http://www.toutiao.com/a6392135944652587266/?tt_from=weixin&utm_campaign=client_share&app ...

  10. 洛谷 P2945 [USACO09MAR]沙堡Sand Castle

    传送门 题目大意: ai,ai+1,ai+2... 变成 bi,bi+1,bi+2.. 不计顺序,增加和减少a数组均有代价. 题解:贪心+排序 小的对应小的 代码: #include<iostr ...