Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5386282

Browse files
committedSep 22, 2021
Add solution #349
1 parent 46271f1 commit 5386282

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
264|[Ugly Number II](./0264-ugly-number-ii.js)|Medium|
3030
283|[Move Zeroes](./0283-move-zeroes.js)|Easy|
3131
345|[Reverse Vowels of a String](./0345-reverse-vowels-of-a-string.js)|Easy|
32+
349|[Intersection of Two Arrays](./0349-intersection-of-two-arrays.js)|Easy|
3233
350|[Intersection of Two Arrays II](./0350-intersection-of-two-arrays-ii.js)|Easy|
3334
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|
3435
451|[Sort Characters By Frequency](./0451-sort-characters-by-frequency.js)|Medium|
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* 349. Intersection of Two Arrays
3+
* https://leetcode.com/problems/intersection-of-two-arrays/
4+
* Difficulty: Easy
5+
*
6+
* Given two integer arrays `nums1` and `nums2`, return an array of their intersection.
7+
*
8+
* Each element in the result must be unique and you may return the result in any order.
9+
*/
10+
11+
/**
12+
* @param {number[]} nums1
13+
* @param {number[]} nums2
14+
* @return {number[]}
15+
*/
16+
var intersection = function(nums1, nums2) {
17+
const set = new Set(nums1);
18+
return nums2.filter(value => set.delete(value));
19+
};

0 commit comments

Comments
 (0)
Please sign in to comment.