leetcode599
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的更多相关文章
- [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 ...
- Leetcode599.Minimum Index Sum of Two Lists
假设Andy和Doris想在晚餐时选择一家餐厅,并且他们都有一个表示最喜爱餐厅的列表,每个餐厅的名字用字符串表示. 你需要帮助他们用最少的索引和找出他们共同喜爱的餐厅. 如果答案不止一个,则输出所有答 ...
随机推荐
- win8 商店应用 设计风格原则
共八条: 1,突出内容(数据). a,仅在屏幕上保留最相关的元素:移除线条.框和不必要的图形效果:限制屏幕上持久显示的导航框,如选项卡. b,交互尽量直接在内容上,直接控制内容来完成操作,而不是使用控 ...
- ZOJ 3498 Javabeans(找规律)
Javabeans Time Limit: 2 Seconds Memory Limit: 65536 KB Javabeans are delicious. Javaman likes t ...
- 早上来开启eclipse,谁想代码都不见了,猜想是工作空间换了
1.试了下网上说的改eclipse配置文件,不好使,连接地址:http://blog.csdn.net/gnail_oug/article/details/53992580 2.然后看了下 eclip ...
- 用 hash 找出指定一个数, 这个数是数组两个值的总和, 找出两个值的坐标
var twoSum = function(nums, target) { var len = nums.length; var exist = {} //这里利用了hash来存放已知的 exist[ ...
- 转一篇pgpool配置
转一篇pgpool配置 http://dz.sdut.edu.cn/blog/subaochen/2013/08/postgresql-9-1的failover配置及其管理/ 环境介绍 在两台虚拟机上 ...
- 由PostgreSQL的区域与字符集说起(转)
转自:http://blog.chinaunix.net/uid-354915-id-3502551.html 由PostgreSQL的区域与字符集说起 一.PostgreSQL的区域区域属性有以下几 ...
- jQuery对象[0]倒底是什么?
s[0]倒底是什么?(s为jQuery对象)代码:var s=$("div"); alert(s.length);alert(s[0]); jQuery对象默认都有个0索引,s为j ...
- not
x = [] print(x) print(not x) print(x is None) print(not x is None) print(x is not None)
- JDBC 3 通过PreparedStatement 对数据库进行增删改查
下面程序沿用上面的封装. 1 插入数据 public boolean ChaRu3(User user){ boolean flag=true; Connection conn=null; Prepa ...
- Vue中render: h => h(App)的含义
// ES5 (function (h) { return h(App); }); // ES6 h => h(App); 官方文档 render: function (createElemen ...