思路:把要删除的节点的下一个节点的值放到被删除的节点处,删除下一个节点.
/**
* 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->next == NULL || node == NULL) return;
node->val = node->next->val;
node->next = node->next->next;
}
};