17.leetcode237. Delete Node in a Linked List

mac2022-06-30  69

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.

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

 

转载于:https://www.cnblogs.com/vincent93/p/6686540.html

最新回复(0)