You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
344 B
Ruby

def remove_ll_duplicates(root)
return false unless root
seen = {}
current = root
while current
if seen[current.val]
remove_node(current)
else
seen[current.val] = true
current = current.next
end
end
end
def remove_node(node)
node.val = node.next.val || nil
node.next = node.next.next
end