第7讲2*
/**
//法1
* 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) {//传入要删除的结点地址
node -> val = node -> next -> val;//把自己伪装成下一个点
node -> next = node -> next -> next;//将下一个点删去
}
};
/**
//法2
* 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) {
*(node) = *(node -> next); //结构体整体复制
}
};