349.Intersection-of-Two-Arrays

349. Intersection of Two Arrays

题目地址

https://leetcode.com/problems/intersection-of-two-arrays/

题目描述

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.

代码

Approach #1 Two Sets

Approach #2 Built-in Set Intersection

Approach #3 Two Pointer

Last updated

Was this helpful?