Problem statement

https://binarysearch.com/problems/Remove-Duplicates-in-Linked-List/

Solution

Just traverse list and keep set of visited nodes.

Complexity

It is O(n) for time and space.

Code

class Solution:
    def solve(self, node):
        V = set()
        head = node
        prev = None
        while node is not None:
            if node.val in V:
                prev.next = node.next
                node = node.next
                continue
            V.add(node.val)
            prev = node
            node = node.next
        return head