leetcode599
Posted AsenYang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode599相关的知识,希望对你有一定的参考价值。
public class Solution { public string[] FindRestaurant(string[] list1, string[] list2) { var dic = new Dictionary<string, int>(); for (int i = 0; i < list1.Length; i++) { for (int j = 0; 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的主要内容,如果未能解决你的问题,请参考以下文章
#Leetcode# 599. Minimum Index Sum of Two Lists
[leetcode-599-Minimum Index Sum of Two Lists]
LeetCode 599. Minimum Index Sum of Two Lists