HTMLify

LeetCode - Minimum Index Sum of Two Lists - Python
Views: 22 | Author: abh
class Solution:
    def findRestaurant(self, list1: list[str], list2: list[str]) -> list[str]:
        lis = len(list1+list2)+1
        ans = []
        for w1 in list1:
            if w1 in list2:
                w1i = list1.index(w1)
                w2i = list2.index(w1)
                s = w1i + w2i
                if s < lis:
                    ans.clear()
                    lis = s
                if s == lis:
                    ans.append(w1)
        return ans

Comments