π
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.