Jul 4, 2024
[1, 1, 2, 2, 3, 3, 4, 4]
[1, 2, 3, 4]
current = head
while current is not None and current.next is not None:
if current.value == current.next.value:
current.next = current.next.next
else:
current = current.next
[1, 2, 3, 4, 2, 3, 4, 5]
seen = set()
result = []
for item in list:
if item not in seen:
seen.add(item)
result.append(item)
if current.value != current.next.value:
current = current.next
else:
current.next = current.next.next
[1, 2, 3, 4, 5, 6]
[1, 2, 3]
and [4, 5, 6]
slow
and fast
.fast
reaches the end.