Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. The linked list will have unique values. You are given the node to delete, and you should delete it in-place. Example: Input: head = [4,5,1,9], node = 5 (the node to delete) Operation: Delete the node with value 5. After deletion: [4,1,9] Explanation: Copy the next node's value to the given node and bypass it. Pattern focus: Pointer Rewiring.
node = ListNode
return void
Example 1:
Input:
head = [4,5,1,9] nodeVal = 5
Output:
[4,1,9]
Explanation:
Deleted node 5 by copying next node 1's data.