Skip to content

Instantly share code, notes, and snippets.

@bt4R9
Created May 21, 2018 15:03
Show Gist options
  • Save bt4R9/ba71b1e4a5c7076fa1945bbd8ab972d6 to your computer and use it in GitHub Desktop.
Save bt4R9/ba71b1e4a5c7076fa1945bbd8ab972d6 to your computer and use it in GitHub Desktop.
var intersect = function(nums1, nums2) {
let fn = (a, b) => a - b;
nums1.sort(fn);
nums2.sort(fn);
let res = [];
let i = 0;
let j = 0;
while (i < nums1.length && j < nums2.length) {
if (nums1[i] === nums2[j]) {
res.push(nums1[i]);
i++;
j++;
} else if (nums1[i] < nums2[j]) {
i++;
} else {
j++;
}
}
return res;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment