Skip to content

Commit 6fcc91c

Browse files
committed
updates
1 parent 3290352 commit 6fcc91c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

data_structures/linked_list/remove_duplicates.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def print_linked_list(head: Node | None) -> None:
3131
print(head.data)
3232

3333

34-
def insert_node(head: Node | None, data: int) -> Node:
34+
def insert_node(head: Node | None, data: int) -> Node | None:
3535
"""
3636
Insert a new node at the end of a linked list
3737
and return the new head.
@@ -78,7 +78,9 @@ def remove_duplicates(head: Node | None) -> Node | None:
7878
new_head = head
7979
last_node = head
8080
has_occurred[head.data] = True
81-
current_node = head.next_node
81+
current_node = None
82+
if head.next_node:
83+
current_node = head.next_node
8284
while current_node is not None:
8385
if current_node.data not in has_occurred:
8486
last_node.next_node = current_node

0 commit comments

Comments
 (0)