mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-03 19:16:27 +00:00
28. 在O(1)时间删除链表结点
https://www.acwing.com/problem/content/submission/code_detail/14064288/
This commit is contained in:
parent
af3743ba87
commit
0fbecbac25
17
AcWing/28/28.cpp
Normal file
17
AcWing/28/28.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user