Day 26: Problem 349, intersection of two arrays
Address: leetcode-cn.com/problems/in…
Find the same value in indexOf, and then delete the duplicate value.
var intersection = function(nums1, nums2) { let a = nums1.filter(val => nums2.indexOf(val) > -1).sort((a,b) => a-b); For (let I = 0; i < a.length - 1; I++) / / delete duplicates {the if (a = = [I] a [I + 1]) {a.s plice (I + 1, 1); i--; } } return a; };Copy the code
Execution time: 84 ms, beating 80.78% of users in all JavaScript commits
Memory consumption: 38.9 MB, beating 33.26% of all JavaScript commits