# LeetCode 349. Intersection of Two Arrays

## Description

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

Example 1:

Input: nums1 = [1,2,2,1], nums2 = [2,2]

Output: [2]

Example 2:

Input: nums1 = [4,9,5], nums2 = [9,4,9,8,4]

Output: [9,4]

Note:

Each element in the result must be unique.

The result can be in any order.

## 描述

### 思路

• python 内置 set 集合可以完成交运算，然后再转换为 List 即可。

# -*- coding: utf-8 -*-
# @Author:             何睿
# @Create Date:        2019-04-09 16:11:29
class Solution:
def intersection(self, nums1: [int], nums2: [int]) -> [int]:
# python 内置集合运算
return list(set(nums1) & set(nums2))

|
11月前
|

LeetCode刷题---Two Sum（一）
LeetCode刷题---Two Sum（一）
|
9月前
Leetcode 4. Median of Two Sorted Arrays

21 0
|
11月前
|

|

LeetCode - #2 Add Two Numbers

64 0
|

LeetCode - #1 Two Sum

48 0
LeetCode 350. Intersection of Two Arrays II

60 0
LeetCode 160. Intersection of Two Linked Lists

54 0
LeetCode 167 Two Sum II - Input array is sorted（输入已排序数组，求其中两个数的和等于给定的数）

74 0
|
Python
LeetCode 21. 合并两个有序链表 Merge Two Sorted Lists
LeetCode 21. 合并两个有序链表 Merge Two Sorted Lists
81 0
|

LeetCode 350. 两个数组的交集 II ntersection of Two Arrays II
LeetCode 350. 两个数组的交集 II ntersection of Two Arrays II
95 0