There is a singly-linked list head and you want to delete a node in it. You are given the node to be deleted node. You will not be given access to the first node of head. All the values of the linked list are unique, and it is guaranteed that the given node is not the last node in the linked list. Delete the given node. Note that by deleting the node, we do not mean removing it from memory. We mean: - The value of the given node should not exist in the linked list. - The number of nodes in the linked list should decrease by one. - All the values before and after the given node should be in the same order. The test harness supplies the list and the value of the node to delete; the function receives only that node.
Example 1
Input: head = [4,5,1,9], node = 5
Output: [4,1,9]
Explanation: Deleting the node with value 5 leaves 4 -> 1 -> 9.
Example 2
Input: head = [4,5,1,9], node = 1
Output: [4,5,9]
Explanation: Deleting the node with value 1 leaves 4 -> 5 -> 9.
Example 3
Input: head = [1,2,3,4], node = 3
Output: [1,2,4]
Explanation: Removing the node that holds 3 links 2 directly to 4. The list becomes 1 -> 2 -> 4.
You cannot reach the previous node, but you can make this node impersonate its successor: copy the next node's value here, then unlink the next node.
Run checks all cases above. Submit evaluates all test cases.