Skip to content

Instantly share code, notes, and snippets.

@Julisam
Created April 9, 2021 22:56
Show Gist options
  • Save Julisam/211f1762def590be0d016bfe1927b758 to your computer and use it in GitHub Desktop.
Save Julisam/211f1762def590be0d016bfe1927b758 to your computer and use it in GitHub Desktop.
Algorithm Fridays Code Snippet
def remove_duplicates(input_array):
"""
Given a sorted array containing duplicates this function
returns the length of the array without the duplicates
i.e. the number of unique items in the array
Input: nums=[0,0,1,1,2,2,3,3,4]
Output: 5
# O(n) time, O(1) space complexity
"""
return len(set(input_array))
@Julisam
Copy link
Author

Julisam commented Apr 17, 2021

Thank you for your feedback.
I'm really grateful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment