题目:
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.
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
void deleteNode(struct ListNode* node) {
if(node != NULL && node->next != NULL) {
node->val = node->next->val;
node->next = node->next->next;
}
}
删除链表节点
本文介绍了一个函数,该函数用于删除单链表中的指定节点(除尾节点外),仅需访问该节点。通过修改节点值及指向下一个节点的指针实现删除操作。
993

被折叠的 条评论
为什么被折叠?



