Skip to content

Commit 7c29ea8

Browse files
committed
✅ [2215] set
1 parent 661044f commit 7c29ea8

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

2215/my_solution.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @param {number[]} nums1
3+
* @param {number[]} nums2
4+
* @return {number[][]}
5+
*/
6+
var findDifference = function (nums1, nums2) {
7+
let nums1Set = new Set(), nums2Set = new Set()
8+
9+
for (let i = 0; i < nums1.length; i++) {
10+
nums1Set.add(nums1[i])
11+
}
12+
13+
for (let i = 0; i < nums2.length; i++) {
14+
nums2Set.add(nums2[i])
15+
}
16+
17+
// {1,2,3} , {1,2}
18+
19+
let result = [[], []] // 0 nums1, 1 nums2
20+
for (let key of nums1Set) {
21+
if (!(nums2Set.has(key))) result[0].push(key)
22+
}
23+
24+
for (let key of nums2Set) {
25+
if (!(nums1Set.has(key))) result[1].push(key)
26+
}
27+
28+
return result;
29+
};

2215/solution.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @param {number[]} nums1
3+
* @param {number[]} nums2
4+
* @return {number[][]}
5+
*/
6+
var findDifference = function (nums1, nums2) {
7+
let nums1Set = new Set(), nums2Set = new Set(), result = [[], []]
8+
9+
for (let i = 0; i < nums1.length; i++) {
10+
nums1Set.add(nums1[i])
11+
}
12+
13+
for (let i = 0; i < nums2.length; i++) {
14+
nums2Set.add(nums2[i])
15+
}
16+
17+
for (let key of nums1Set) {
18+
if (!(nums2Set.has(key))) result[0].push(key)
19+
}
20+
21+
for (let key of nums2Set) {
22+
if (!(nums1Set.has(key))) result[1].push(key)
23+
}
24+
25+
return result;
26+
};

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
- [1909. Remove One Element to Make the Array Strictly Increasing](./1909/)
120120
- [1971. Find if Path Exists in Graph](./1971/)
121121
- [2090. K Radius Subarray Averages](./2090/)
122+
- [2215. Find the Difference of Two Arrays](./2215/)
122123
- [2373. Largest Local Values in a Matrix](./2373/)
123124
- [2448. Minimum Cost to Make Array Equal](./2448/)
124125

@@ -168,7 +169,7 @@ Batch create:
168169
NOTE: JS IS HERE
169170
-->
170171
```ssh
171-
chapter=724 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
172+
chapter=2215 && mkdir ./$chapter && touch ./$chapter/my_solution.js && touch ./$chapter/solution.js && alias x="node ./$chapter/my_solution.js"
172173
```
173174
> then you can use `x` for quick debug.
174175

0 commit comments

Comments
 (0)