:type list1: List[str] :type list2: List[str] :rtype: List[str]
(self, list1, list2)
| 38 | |
| 39 | class 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 |