Practice/Meta/Leetcode 237. Delete Node in a Linked List
CodingOptional
You are given access to a node in a singly linked list that is not the tail node. Your task is to delete that node from the linked list.
The catch: you are only given the node to be deleted. You do not have access to the head of the list or any other nodes before the target node.
Write a function that deletes the given node from the linked list.
[2, 1000]-1000 <= Node.val <= 1000node to be deleted is in the list and is not the tail nodeExample 1:
Input: head = [4,5,1,9], node = 5 (the second node) Output: [4,1,9] Explanation: You are given the node with value 5. After calling your function, the linked list should become 4 -> 1 -> 9
Example 2:
Input: head = [4,5,1,9], node = 1 (the third node) Output: [4,5,9] Explanation: You are given the node with value 1. After calling your function, the linked list should become 4 -> 5 -> 9
Example 3:
Input: head = [1,2,3,4], node = 3 (the third node) Output: [1,2,4] Explanation: After deletion, the list becomes 1 -> 2 -> 4