Intersection of Two Arrays II LeetCode solution in Python
1class Solution:2def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:3nums1.sort()4nums2.sort()5ans = []6i, j = 0, 07while i < len(nums1) and j < len(nums2):8if nums1[i] < nums2[j]:9i += 110elif nums1[i] > nums2[j]:11j += 112else:13ans.append(nums1[i])14i += 115j += 116return ans