4lines python solution but takes long time


  • 0
    L
        def intersect(self, nums1, nums2):
            """
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: List[int]
            """
            r = []
            for ele in set(nums1).intersection(set(nums2)):
                n = nums1.count(ele) if nums1.count(ele)<nums2.count(ele) else nums2.count(ele)
                r.extend([ele]*n)
            return r

Log in to reply
 

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