0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

28. 在O(1)时间删除链表结点

https://www.acwing.com/problem/content/submission/code_detail/14064288/
This commit is contained in:
Baoshuo Ren 2022-05-09 19:31:24 +08:00
parent af3743ba87
commit 0fbecbac25
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

17
AcWing/28/28.cpp Normal file
View File

@ -0,0 +1,17 @@
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
void deleteNode(ListNode* node) {
ListNode* tmp = node->next;
node->val = node->next->val;
node->next = node->next->next;
delete tmp;
}
};