Python | Leetcode Python题解之第350题两个数组的交集II
题目:

题解:
class Solution:def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:nums1.sort()nums2.sort()length1, length2 = len(nums1), len(nums2)intersection = list()index1 = index2 = 0while index1 < length1 and index2 < length2:if nums1[index1] < nums2[index2]:index1 += 1elif nums1[index1] > nums2[index2]:index2 += 1else:intersection.append(nums1[index1])index1 += 1index2 += 1return intersection