mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Update data_structures/arrays/intersection.rb
Co-authored-by: Vitor Oliveira <vbrazo@gmail.com>
This commit is contained in:
parent
db2d1b74a2
commit
5c1580fc10
1 changed files with 8 additions and 1 deletions
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue