题目:
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 is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, the linked list should become 1 -> 2 -> 4 after calling your function.
Language C:
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
// 给定节点的next覆盖当前节点
void deleteNode(struct ListNode* node) {
node->val = node->next->val; //后一节点的值赋值给当前节点的值
node->next = node->next->next; //给定节点的next指向给定节点的next的next
}