We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6204a77 commit 0bcaebaCopy full SHA for 0bcaeba
350-intersection-of-two-arrays-ii.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {number[]} nums1
3
+ * @param {number[]} nums2
4
+ * @return {number[]}
5
+ */
6
+const intersect = function(nums1, nums2) {
7
+ const res = []
8
+ const map = {}
9
+ for(let i = 0; i < nums1.length; i++) {
10
+ if(map.hasOwnProperty(nums1[i])) {
11
+ map[nums1[i]] += 1
12
+ } else {
13
+ map[nums1[i]] = 1
14
+ }
15
16
+
17
+ for(let j = 0; j < nums2.length; j++) {
18
+ if(map.hasOwnProperty(nums2[j]) && map[nums2[j]] > 0) {
19
+ res.push(nums2[j])
20
+ map[nums2[j]] -= 1
21
22
23
24
+ return res
25
+};
0 commit comments