17.leetcode 237. Delete Node in a Linked List

时间:2021-09-04 23:14:12

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 -> 4after calling your function.

思路:单向链表,只给出要删除的结点的指针。因为我们无法获得要删除的节点的上一个结点的地址,所以就把要删除结点的下一个结点的值复制到要删除的节点,然后删掉要删除结点的下一个结点。

17.leetcode  237. Delete Node in a Linked List