We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3290352 commit 6fcc91cCopy full SHA for 6fcc91c
data_structures/linked_list/remove_duplicates.py
@@ -31,7 +31,7 @@ def print_linked_list(head: Node | None) -> None:
31
print(head.data)
32
33
34
-def insert_node(head: Node | None, data: int) -> Node:
+def insert_node(head: Node | None, data: int) -> Node | None:
35
"""
36
Insert a new node at the end of a linked list
37
and return the new head.
@@ -78,7 +78,9 @@ def remove_duplicates(head: Node | None) -> Node | None:
78
new_head = head
79
last_node = head
80
has_occurred[head.data] = True
81
- current_node = head.next_node
+ current_node = None
82
+ if head.next_node:
83
+ current_node = head.next_node
84
while current_node is not None:
85
if current_node.data not in has_occurred:
86
last_node.next_node = current_node
0 commit comments