Created
April 9, 2021 22:56
-
-
Save Julisam/211f1762def590be0d016bfe1927b758 to your computer and use it in GitHub Desktop.
Algorithm Fridays Code Snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for your feedback.
I'm really grateful.