-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution.py
More file actions
23 lines (21 loc) · 748 Bytes
/
solution.py
File metadata and controls
23 lines (21 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution(object):
def findRestaurant(self, list1, list2):
"""
:type list1: List[str]
:type list2: List[str]
:rtype: List[str]
"""
res = []
resturant_map = {}
min_index_sum = sys.maxint
for i in range(0, len(list1)):
resturant_map[list1[i]] = i
for i in range(0, len(list2)):
if resturant_map.get(list2[i]) != None:
index_sum = resturant_map.get(list2[i]) + i
if index_sum < min_index_sum:
res = [list2[i]]
min_index_sum = index_sum
elif index_sum == min_index_sum:
res.append(list2[i])
return res