52ms Python solution


  • 1
    L
    class Solution(object):
        def intersect(self, nums1, nums2):
            """
            :type nums1: List[int]
            :type nums2: List[int]
            :rtype: List[int]
            """
            nums1.sort()
            nums2.sort()
            result = []
            while nums1 and nums2:
                if nums2[0] == nums1[0]:
                    result.append(nums2.pop(0))
                    nums1.pop(0)
                else:
                    if nums2[0] > nums1[0]:
                        nums1.pop(0)
                    else:
                        nums2.pop(0)
            return result
    

Log in to reply
 

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