mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
23 lines
413 B
Ruby
23 lines
413 B
Ruby
|
# Challenge name: Intersection of two arrays ii
|
||
|
#
|
||
|
# Given two arrays, write a function to compute their intersection.
|
||
|
#
|
||
|
# @param {Integer[]} nums1
|
||
|
# @param {Integer[]} nums2
|
||
|
# @return {Integer[]}
|
||
|
|
||
|
#
|
||
|
# Approach 1:
|
||
|
#
|
||
|
# Time Complexity:
|
||
|
#
|
||
|
def intersect(arr1, arr2)
|
||
|
end
|
||
|
nums1 = [1, 2, 2, 1]
|
||
|
nums2 = [2, 2]
|
||
|
intersect(nums1, nums2)
|
||
|
# => [2,2]
|
||
|
nums1 = [4, 9, 5]
|
||
|
nums2 = [9, 4, 9, 8, 4]
|
||
|
intersect(nums1, nums2)
|
||
|
# => [4,9]
|