<reponame>pauvrepetit/leetcode
# 350. 两个数组的交集 II
#
# 20200811
# huao
# 排序比较慢 不排序又不会写...

from typing import List


class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        nums1.sort()
        nums2.sort()
        inter = []
        i = 0
        j = 0
        while i < len(nums1) and j < len(nums2):
            if nums1[i] == nums2[j]:
                inter.append(nums1[i])
                i += 1
                j += 1
            elif nums1[i] > nums2[j]:
                j += 1
            else:
                i += 1
        return inter

# 350. 两个数组的交集 II
#
# 20200811
# huao
# 排序比较慢 不排序又不会写...

from typing import List


class Solution:
    def intersect(self, nums1: List[int], nums2: List[int]) -> List[int]:
        nums1.sort()
        nums2.sort()
        inter = []
        i = 0
        j = 0
        while i < len(nums1) and j < len(nums2):
            if nums1[i] == nums2[j]:
                inter.append(nums1[i])
                i += 1
                j += 1
            elif nums1[i] > nums2[j]:
                j += 1
            else:
                i += 1
        return inter
# 350. 两个数组的交集 II # # 20200811 # huao # 排序比较慢 不排序又不会写...