Delete a node from a singly linked list when only that node is given.
You are given a reference to a node in a singly linked list. The node to delete is not the tail of the list.
Remove that node from the list so that the linked list no longer contains it, and the relative order of the remaining nodes stays the same.
You do not have access to the head of the list.
Because the head is unavailable, you cannot simply search for the previous node. Instead, you must modify the list in place using only the given node.
Update the linked list so that the given node is logically deleted from the chain.
Return nothing. Modify the linked list in place by deleting the given node.
Example 1
Input
head = [4,5,1,9], node = 5
Output
head = [4,1,9]
Explanation
Copy the value from the next node into the given node, then bypass the next node. The list becomes 4 -> 1 -> 9.
Example 2
Input
head = [1,2,3,4], node = 3
Output
head = [1,2,4]
Explanation
The node with value 3 is replaced in place by its next node's value, and the next node is removed from the chain.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.