LintCode: Delete Node in the Middle of Singly Linked List

开始没看懂题目的意思,以为是输入一个单链表,删掉链表中间的那个节点。

实际的意思是,传入的参数就是待删节点,所以只要把当前节点指向下一个节点就可以了。

C++

 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         node->val = node->next->val;
22         node->next = node->next->next;
23     }
24 };
原文地址:https://www.cnblogs.com/CheeseZH/p/5012617.html