Imagine you're given a mysterious mission: delete a specific node from a singly-linked list, but here's the twist - you don't have access to the head of the list!
You are given only the node to be deleted, and it's guaranteed that this node is not the last node in the list. All values in the linked list are unique.
Your goal: Make this node "disappear" from the linked list without having access to the previous nodes or the head. The list should maintain its structure and order, just without the target node.
Note: We don't mean removing it from memory completely - we mean the node's value should no longer exist in the logical structure of the list, and the list length should decrease by one.
Example: If the list is 4 -> 5 -> 1 -> 9 and you need to delete node with value 5, the result should be 4 -> 1 -> 9.
Input & Output
Constraints
-
The number of nodes in the given list is in the range
[2, 1000] -
-1000 <= Node.val <= 1000 - The value of each node in the list is unique
-
The
nodeto be deleted is in the list and is not a tail node