3-line Python solution

  • 0

    Ordinary solution using dictionaries with comprehensions to make it short.

    class Solution(object):
        def findRestaurant(self, l1, l2):
            :type list1: List[str]
            :type list2: List[str]
            :rtype: List[str]
            d1=dict((l1[i],i) for i in xrange(len(l1)))
            d2=dict((l2[j],j+d1[l2[j]]) for j in xrange(len(l2)) if l2[j] in d1.keys())
            return [d2.keys()[i] for i in xrange(len(d2)) if d2.values()[i]==min(d2.values())]

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.