• + 0 comments

    Here is a general solution because I didn't read the entire specification 🤡

        def removeDuplicates(self,head):
            head_data = head.data
            
            result_head = Node(head_data)         
            previous_result_node = result_head
            
            elements = list()  
            elements.append(head_data)
            
            node = head.next        
            while node is not None:  
                node_data = node.data          
                if node_data not in elements:                
                    result_node = Node(node_data)              
                    previous_result_node.next = result_node
                    previous_result_node = result_node
                                   
                    elements.append(node_data)
                    
                node = node.next
            
            return result_head