Simple Python solution


  • 0
    C
    L1 = dict(zip(list1,range(len(list1))))
    L2 = dict(zip(list2,range(len(list2))))
    A = len(L1)+len(L2)
    F = {}
    for key in L1:
         try:
            if (L1[key]+L2[key])<=A:
                A = L1[key]+L2[key]
                try:
                    F[A].append(key)
                except:
                    F[A] = [key]
        except:
            pass
    return F[A]
                    
    

Log in to reply
 

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