Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.
Supposed the linked list 1 -> 2 -> 3 -> 4
is and you were given the third node with value 3
, the linked list should become 1 -> 2 -> 4
a Fter calling your function.
https://leetcode.com/problems/delete-node-in-a-linked-list/
Deletes a given node in a single-linked list, but does not give the table header of the linked list.
The solution is simple, the value of the latter node is overwritten with the value of the current node, and finally, the last node is deleted.
1 /**2 * @param {listnode} node3 * @return {void} does not return anything, modify node In-place instead.4 */5 varDeletenode =function(node) {6 varPrevious =node;7 Delnode (node.next);8 return;9 Ten functionDelnode (n) { OnePrevious.val =N.val; A if(N.next = = =NULL){ -Previous.next =NULL; -}Else{ thePrevious =Previous.next; -n =N.next; - Delnode (n); - } + } -};
[Leetcode] [JavaScript] Delete Node in a Linked List