Update data_structures/arrays/intersection.rb

Co-authored-by: Vitor Oliveira <vbrazo@gmail.com>
This commit is contained in:
Jessica Kwok 2021-04-19 15:55:22 -07:00 committed by GitHub
parent db2d1b74a2
commit 5c1580fc10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,7 +46,14 @@ puts intersect(nums1, nums2)
#
# Approach 2: Hash
#
# Time Complexity: O(n)
# Complexity Analysis
#
# Time Complexity: O(n+m), where n and m are the lengths of the arrays.
# We iterate through the first, and then through the second array; insert
# and lookup operations in the hash map take a constant time.
#
# Space Complexity: O(min(n,m)). We use hash map to store numbers (and their
# counts) from the smaller array.
#
def intersect(arr1, arr2)
result = []