Add complexity analysis

This commit is contained in:
Vitor Oliveira 2021-03-15 21:42:53 -07:00
parent ad35c2398c
commit afef73db10

View file

@ -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