Skip to content

Commit 43e85d7

Browse files
committedJan 5, 2025
Add solution #2215
1 parent 3407b5d commit 43e85d7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@
364364
2114|[Maximum Number of Words Found in Sentences](./2114-maximum-number-of-words-found-in-sentences.js)|Easy|
365365
2129|[Capitalize the Title](./2129-capitalize-the-title.js)|Easy|
366366
2154|[Keep Multiplying Found Values by Two](./2154-keep-multiplying-found-values-by-two.js)|Easy|
367+
2215|[Find the Difference of Two Arrays](./2215-find-the-difference-of-two-arrays.js)|Easy|
367368
2235|[Add Two Integers](./2235-add-two-integers.js)|Easy|
368369
2244|[Minimum Rounds to Complete All Tasks](./2244-minimum-rounds-to-complete-all-tasks.js)|Medium|
369370
2396|[Strictly Palindromic Number](./2396-strictly-palindromic-number.js)|Medium|
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* 2215. Find the Difference of Two Arrays
3+
* https://leetcode.com/problems/find-the-difference-of-two-arrays/
4+
* Difficulty: Easy
5+
*
6+
* Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where:
7+
* - answer[0] is a list of all distinct integers in nums1 which are not present in nums2.
8+
* - answer[1] is a list of all distinct integers in nums2 which are not present in nums1.
9+
*
10+
* Note that the integers in the lists may be returned in any order.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums1
15+
* @param {number[]} nums2
16+
* @return {number[][]}
17+
*/
18+
var findDifference = function(nums1, nums2) {
19+
const set1 = new Set(nums1);
20+
const set2 = new Set(nums2);
21+
return [
22+
[...set1].filter(n => !set2.has(n)),
23+
[...set2].filter(n => !set1.has(n))
24+
];
25+
};

0 commit comments

Comments
 (0)
Please sign in to comment.