1 /** 2 * Definition of ListNode 3 * class ListNode { 4 * public: 5 * int val; 6 * ListNode *next; 7 * ListNode(int val) { 8 * this->val = val; 9 * this->next = NULL; 10 * } 11 * } 12 */ 13 class Solution { 14 public: 15 /** 16 * @param node: a node in the list should be deleted 17 * @return: nothing 18 */ 19 void deleteNode(ListNode *node) { 20 // write your code here 21 ListNode* next = node -> next; 22 node -> val = next -> val; 23 node -> next = next -> next; 24 next -> next = NULL; 25 delete next; 26 } 27 };
时间: 2024-10-21 21:06:20