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. opencv:访问像素

    a.使用指针 #include <opencv.hpp> using namespace cv; using namespace std; int main() { //指针访问每个像素并 ...

  2. 第七次scrum meeting记录

    文章负责:张华杰 日期:2017年10月31日 会议地点:主楼主南201 各组员工作情况 团队成员 昨日完成任务 明日要完成任务 赵晓宇 课程列表页面搭建 issue20 课程列表页面搭建(part ...

  3. UI- 不易记知识点汇总

    1.static: 所有的全局变量都是静态变量,而局部变量只有定义时加上类型修饰符static,才为局部静态变量. 静态变量并不是说其就不能改变值,不能改变值的量叫常量. 其拥有的值是可变的 ,而且它 ...

  4. dubbo常见报错

    1. java.io.IOException: Can not lock the registry cache file C:\Users\Administrator\.dubbo\dubbo-reg ...

  5. windows获取屏幕显示比例 读取注册表法

    static int GetDesktopScale() { ; HINSTANCE hUser32 = LoadLibrary(L"user32.dll"); if (hUser ...

  6. go set up on ubuntu

    sudo apt-get install golang-go package main import ( "fmt" "runtime" ) func main ...

  7. 剑指offer—第二章算法之快速排序

    算法:排序和查找(二分查找,归并排序,快速排序),位运算等. 查找:顺序查找,哈希查找,二叉排序树查找,哈希表. 二分查找可以解决:"旋转数组中的最小数字","数字在排序 ...

  8. 【操作系统】总结五(I/O管理)

    输入输出管理本章主要内容: I/O管理概述(I/O控制方式.I/O软件层次结构)和I/O核心子系统(I/O调度概念.局速缓存与缓冲区.设备分配与回收.假脱机技术(SPOOLing)). 5.1 I/O ...

  9. Oracle数据文件和临时文件的管理

    一.数据文件概述在Oracle数据库中,SYSTEM和SYSAUX表空间至少需要包含一个数据文件,此外还将包含多个其他表空间及与其相关的数据文件和临时文件.Oracle的数据文件和临时文件是操作系统文 ...

  10. (转)TextView 设置背景和文本颜色的问题

    在做一个项目,突然遇到如下问题 比如:在color.xml中定义了几个颜色 <color name="white">#FFFFFF</color> < ...