Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Delete Node in a Linked List

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.




该题目也可以描述为: 如何在O(1)的时间删除单链表的某个节点!

void deleteNode(ListNode *node) {
	ListNode *p = node->next;
	node->val = p->val;
	node->next = p->next;
	delete p;
You can’t perform that action at this time.