interviews
interviews copied to clipboard
Remove Duplicates from a Sorted List
Added Remove Duplicates from a Sorted List. Leetcode Problem .83
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.