Intersection of Two Arrays II1 [Leetcode][자바스크립트][Easy] 350. Intersection of Two Arrays II 풀이1 /** * 350_IntersectionOfTwoArraysII.js * Easy * https://leetcode.com/problems/intersection-of-two-arrays-ii/ */ var intersect = function(nums1, nums2) { const answer = [], idxHash = {}; nums1.forEach((num) => { const idx = idxHash[num] === undefined ? nums2.indexOf(num) : nums2.indexOf(num, idxHash[num] + 1); if (idx > -1) { idxHash[num] = idx; answer.push(num); } }); return answer; }; 교집합을 .. 2022. 1. 8. 이전 1 다음