1def delete_node(head, target):
2 if head is None:
3 return None
4 if head.val == target:
5 return head.next
6
7 current = head
8 while current.next:
9 if current.next.val == target:
10 current = current.next
11 break
12 current = current.next
13 return head
no lines flagged
#007PracticeEasy10 min · 50 XP
Linked List Node Leak on Delete
Deleting a node from the middle of a singly linked list leaves a dangling reference. Find the fault.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.