码迷,mamicode.com
首页 > 其他好文 > 详细

LintCode: Delete Node in the Middle of Singly Linked List

时间:2015-12-02 14:25:12      阅读:92      评论:0      收藏:0      [点我收藏+]

标签:

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

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

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 };

 

LintCode: Delete Node in the Middle of Singly Linked List

标签:

原文地址:http://www.cnblogs.com/CheeseZH/p/5012617.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!