【Easy】548. Intersection of Two Arrays II

Given two arrays, write a function to compute their intersection.

Notice:

Each element in the result should appear as many times as it shows in both arrays. The result can be in any order.

解题思路

a. HashMap

b. Sort + Two pointers

时间空间复杂度

a. O(m+n) + S(m)

b. O(nlogn) + S(1)

m为较短的array长度,n为较长的array长度

Last updated