intersection of two arrays -> intersection of k arrays

merge two sorted arrays -> merge k sorted arrays

intersection of two arrays I

找出两个数组的交集,需要去重

  1. 排序较小的数组,然后对大数组中每一个元素在较小的数组中进行二分查找 O(nlogm + mlogm) = O( (n +m) log m) , space O(1)
  2. merge two sorted array (需要set去重) O( nlogn +mlogm + max(m, n)) space O(min(m,n))
  3. hashset 记录其中数组中出现元素的个数 O(n), space O(n) 详情见数据结构

intersection of two arrays II

找出两个数组交集,相同元素有几个就match几个

results matching ""

    No results matching ""