You are viewing a single comment's thread. Return to all comments →
This will remove all duplicates, not just the adjacent ones.
def removeDuplicates(self, head: Node | None): current_node = head s = set((current_node.data, )) while current_node.next: if current_node.next.data not in s: s.add(current_node.next.data) current_node = current_node.next else: current_node.next = current_node.next.next return head
Seems like cookies are disabled on this browser, please enable them to open this website
Day 24: More Linked Lists
You are viewing a single comment's thread. Return to all comments →
This will remove all duplicates, not just the adjacent ones.