interviews icon indicating copy to clipboard operation
interviews copied to clipboard

Remove Duplicates from a Sorted List

Open sonjyoti opened this issue 2 years ago • 1 comments

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

sonjyoti avatar May 23 '23 19:05 sonjyoti

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.

Ziniddoug avatar Jun 01 '23 21:06 Ziniddoug