TheAlgorithms-Ruby/data_structures/arrays/intersection.rb

23 lines
413 B
Ruby
Raw Normal View History

2021-04-01 01:40:23 +02:00
# 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]