首页 > 其他 > 详细

[LintCode] 在O(1)时间复杂度删除链表节点

时间:2015-07-07 21:06:22      阅读:194      评论:0      收藏:0      [点我收藏+]
 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 };

 

[LintCode] 在O(1)时间复杂度删除链表节点

原文:http://www.cnblogs.com/jcliBlogger/p/4628403.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!