# 两数组的交

1. 集合

2. 哈希表

3. 排序+两根指针

class Solution:
# @param {int[]} nums1 an integer array
# @param {int[]} nums2 an integer array
# @return {int[]} an integer array
def intersection(self, nums1, nums2):
return list(set(s1) & set(s2))

class Solution:
# @param {int[]} nums1 an integer array
# @param {int[]} nums2 an integer array
# @return {int[]} an integer array
def intersection(self, nums1, nums2):
hash_table = {}
result = []
hash_table.fromkeys(nums1)
for i in nums2:
if len(hash_table) == 0:
break
if i in hash_table:
result.append(i)
hash_table.pop(i)
return result

class Solution:
# @param {int[]} nums1 an integer array
# @param {int[]} nums2 an integer array
# @return {int[]} an integer array
def intersection(self, nums1, nums2):
result = []
nums1.sort()
nums2.sort()
index1, index2 = 0, 0
n1, n2 = len(nums1), len(nums2)

if n1 == 0 or n2 == 0:
return []

while index1 < n1 and index2 < n2:
if nums1[index1] == nums2[index2]:
temp = nums1[index1]
result.append(temp)
while index1 < n1 and nums1[index1] == temp:
index1 += 1
while index2 < n2 and nums2[index2] == temp:
index2 += 1
elif nums1[index1] > nums2[index2]:
index2 += 1
else:
index1 += 1
return result

#### 两数组的交Ⅱ

2017-06-08 16:55:08

#### LeetCode 两个数组的交集2

2018-06-05 22:44:33

#### 关于LeetCode中Intersection of Two Arrays一题的理解

2016-08-27 12:22:16

#### lintcode 刷题-两数组的交 II Python

2017-03-23 21:49:53

#### 两数组的交 II

2016-06-02 19:21:20

#### 关于LeetCode中Intersection of Two Arrays II一题的理解

2016-08-29 17:24:09

#### Leetcode 349:两个数组的交集（最详细解决方案！！！）

2018-06-04 10:40:11

#### LeetCode - 两个数组的交集 II

2018-03-16 11:27:08

#### 详解重载解析(一)

2016-10-19 15:38:50

#### C语言复习2

2012-04-07 15:09:32