kdn251 / interviews

Everything you need to know to get the job.
https://www.youtube.com/channel/UCKvwPt6BifPP54yzH99ff1g?view_as=subscriber
MIT License
63.47k stars 12.89k forks source link

Remove Duplicates from a Sorted List #231

Open sonjyoti opened 1 year ago

sonjyoti commented 1 year ago

Added Remove Duplicates from a Sorted List. Leetcode Problem .83

Ziniddoug commented 1 year ago
def remove_duplicates(lst):
    unique_lst = []
    for element in lst:
        if element not in unique_lst:
            unique_lst.append(element)
    return unique_lst

# Example usage
lst = [1, 2, 2, 3, 4, 4, 4, 5, 6, 6]
unique_lst = remove_duplicates(lst)
print(unique_lst)

In this example, the remove_duplicates function takes a list as a parameter and iterates over each element in the list. If the element is not already present in the unique_lst, it is added to that list. Finally, the function returns the list without duplicates.

In the provided usage example, the original list is [1, 2, 2, 3, 4, 4, 4, 5, 6, 6]. The output will be [1, 2, 3, 4, 5, 6], which is the original list without duplicates.