📚
Array Intersection
Array Intersection보통 배열 +20pts
Problem
Write a function that returns elements common to both arrays.
Examples
Input:
intersection([1, 2, 3], [2, 3, 4])Output:
[2, 3]Explanation
이 문제는 **filter와 includes**를 조합하여 두 배열의 교집합을 구하는 방법을 학습합니다. ## 핵심 개념: 집합 연산 - 교집합 교집합은 두 집합에 공통으로 존재하는 요소들의 집합입니다. ### 접근 방법 ```javascript arr1.filter(x => arr2.includes(x)) ``` - arr1의 각 요소에 대해 - arr2에 포함되어 있는지 확인 - 포함된 요소만 남김 ### filter와 includes 조합 이 패턴은 집합 연산에서 매우 자주 사용됩니다: - 교집합: filter(x =>...
View detailed explanation →Key Concepts
filter 메서드 includes 메서드 교집합 집합 연산
Time: O(n*m) Space: O(min(n,m))
solution.js
Ctrl + Enter
Run tests to see results here.