mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-13 08:01:03 +01:00
Add complexity analysis
This commit is contained in:
parent
ad35c2398c
commit
afef73db10
1 changed files with 9 additions and 1 deletions
|
@ -54,9 +54,17 @@ puts remove_elements([0,1,2,2,3,0,4,2], 2)
|
|||
# => 5
|
||||
|
||||
#
|
||||
# Approach 3: Two-pointer
|
||||
# Approach 3: Two-pointers
|
||||
#
|
||||
|
||||
# Complexity analysis
|
||||
#
|
||||
# Time complexity: O(n). Both i and n traverse at most n steps.
|
||||
# In this approach, the number of assignment operations is equal to the
|
||||
# number of elements to remove.
|
||||
#
|
||||
# Space complexity: O(1)
|
||||
|
||||
def remove_element(nums, val)
|
||||
pointer1 = 0
|
||||
pointer2 = nums.length
|
||||
|
|
Loading…
Reference in a new issue