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.
Test instructions is very simple and simple, delete the node specified in the single-linked list, look carefully, not ah. Cannot get the precursor node to delete the node, that is, the traditional method cannot be used. If the single-linked list 1->2->3->4->5, we want to delete node 3, you can let 3 is assigned to 4, 3 points to 5. Then it becomes a 1->2->4->5, and ^_^ results are
/* * Definition for singly-linked list. * struct ListNode {* int val; * */void DeleteNo De (struct listnode* node) { if(node==NULL) { return ; } Else { node->val=node->next->val; Node->next=node->next->Next;} }
Leetcode237-delete Node in a Linked List