• + 0 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