We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 43288f4 commit b9edfb9Copy full SHA for b9edfb9
349-intersection-of-two-arrays/intersection-of-two-arrays.js
@@ -0,0 +1,24 @@
1
+/**
2
+ * @param {number[]} nums1
3
+ * @param {number[]} nums2
4
+ * @return {number[]}
5
+ */
6
+var intersection = function(nums1, nums2) {
7
+ nums1.sort((a,b) => a - b);
8
+ nums2.sort((a,b) => a - b);
9
+
10
+ let res = [];
11
+ let i = 0, j = 0;
12
+ while(i < nums1.length && j < nums2.length){
13
+ if( nums1[i] === nums2[j]){
14
+ res.push(nums1[i]);
15
+ i++;
16
+ j++;
17
+ }else if (nums1[i] < nums2[j]){
18
19
+ }else{
20
21
+ }
22
23
+ return [...new Set(res)] ;
24
+};
0 commit comments