https://leetcode.com/problems/delete-node-in-a-linked-list/
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution { 10 public: 11 void deleteNode(ListNode* node) { 12 if(node==NULL||node->next==NULL) 13 return; 14 ListNode * temp; 15 ListNode * tail; 16 temp=node; 17 tail=node->next; 18 while(true) 19 { 20 temp->val=tail->val; 21 if(tail->next==NULL) 22 break; 23 else 24 { 25 temp=tail; 26 tail=tail->next; 27 } 28 } 29 temp->next=NULL; 30 } 31 };