Python easy understand solution

  • 0
    1. Get common words
    2. Calculate index sum using collections.Counter
    3. Find the minimum
    4. Return result
        def findRestaurant(self, l1, l2):
            d = set(l1) & set(l2)
            c = Counter({v: i + 1 for i, v in enumerate(l1) if v in d}) + \
                Counter({v: i + 1 for i, v in enumerate(l2) if v in d})
            res = min(c.values())
            return [i for i, v in c.items() if v == res]

Log in to reply

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