LeetCode 237. Delete Node in a Linked List
1 class Solution { 2 public: 3 void deleteNode(ListNode* node) { 4 if(node == NULL || node->next == NULL){ 5 node = NULL; 6 return; 7 } 8 ListNode* tmp = node->next; 9 node->val = node->next->val; 10 node->next = node->next->next; 11 delete tmp; 12 } 13 };
node:要删除的节点
node->#1->#2
把#1的val赋给node,把node->next改为#2,删除#1.