mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-15 03:43:22 +01:00
Update data_structures/arrays/intersection.rb
Co-authored-by: Vitor Oliveira <vbrazo@gmail.com>
This commit is contained in:
parent
25d76f8944
commit
db2d1b74a2
1 changed files with 5 additions and 2 deletions
|
@ -78,7 +78,10 @@ puts intersect(nums1, nums2)
|
||||||
#
|
#
|
||||||
# Approach 3: Two Pointers
|
# Approach 3: Two Pointers
|
||||||
#
|
#
|
||||||
# Time Complexity: O(n log n)
|
# Complexity analysis:
|
||||||
|
|
||||||
|
# Time Complexity: O(nlogn + mlogm), where n and m are the lengths of the arrays. We sort two arrays independently and then do a linear scan.
|
||||||
|
# Space Complexity: from O(logn+logm) to O(n+m), depending on the implementation of the sorting algorithm.
|
||||||
#
|
#
|
||||||
def intersect(nums1, nums2)
|
def intersect(nums1, nums2)
|
||||||
result = []
|
result = []
|
||||||
|
|
Loading…
Reference in a new issue