Delete Node in a Linked List

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Delete Node in a Linked List相关的知识,希望对你有一定的参考价值。

问题:给一个循环链表,和一个要删除的节点,将其删除。时间复杂度O(n)。核心代码如下:

1 ListNode *next = node->next;
2 ListNode *cur = node;
3 while (cur->next != node)
4     cur = cur->next;
5 cur->next = next;

问题:给一个链表的节点(不是链表尾),将其从链表中删除。核心代码如下:

1 node->val = node->next->val;
2 node->next = node->next->next;

 

以上是关于Delete Node in a Linked List的主要内容,如果未能解决你的问题,请参考以下文章

237. Delete Node in a Linked List

Delete Node in a Linked List

LeetCode237-delete-node-in-a-linked-list

Linked List-237. Delete Node in a Linked List

LC_237.Delete Node in a Linked List

LeetCode:Delete Node in a Linked List