C++示例:
/**
* 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) {
if (node == NULL || node->next == NULL) {
cout << "The node is empty or the node is the rear node." << endl;
return;
}
ListNode* temp = node->next;
node->val = temp->val;
node->next = temp->next;
delete temp;
}
};
原文地址:https://www.cnblogs.com/yiluyisha/p/9266072.html
时间: 2024-10-09 07:18:39