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