You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.
Given two integer arrays nums1 and nums2, return an array of their intersection. Each element in the result must be unique and you may return the result in any order.
Example 1:
Example 2:
Constraints:
1 <= nums1.length, nums2.length <= 1000
0 <= nums1[i], nums2[i] <= 1000
解法一:
求两个数组的交集,思路很简单,用hashtable,涉及到去重,所以这里的hashtable用Set表示。代码如下:
解法二:
将其中一个数组排序,遍历另一个数组,如果另一个数组的元素在已排序的数组中,则该元素为两个数组的交集。用二分查找进行搜索。代码如下:
The text was updated successfully, but these errors were encountered: