MCPcopy
hub / github.com/HuberTRoy/leetCode / findRestaurant

Method findRestaurant

Array/MinimumIndexSumOfTwoLists.py:40–55  ·  view source on GitHub ↗

:type list1: List[str] :type list2: List[str] :rtype: List[str]

(self, list1, list2)

Source from the content-addressed store, hash-verified

38
39class Solution(object):
40 def findRestaurant(self, list1, list2):
41 """
42 :type list1: List[str]
43 :type list2: List[str]
44 :rtype: List[str]
45 """
46 list1_dict = {value:index for index, value in enumerate(list1)}
47 commonInterest = {}
48 for index, value in enumerate(list2):
49 if list1_dict.get(value) is not None:
50 try:
51 commonInterest[index + list1_dict.get(value)].append(value)
52 except KeyError:
53 commonInterest[index + list1_dict.get(value)] = [value]
54
55 return commonInterest[min(commonInterest)]
56

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected