首页 > 其他 > 详细

[LeetCode笔记]-237-Delete Node in a Linklist

时间:2015-09-26 21:05:37      阅读:169      评论:0      收藏:0      [点我收藏+]

上LeetCode后做的第一道题。删除一个链表节点。两个写法。第一个8ms,第二个4ms。先这么写吧。

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
 
 /* solution 1
 // The normal one I can think immediately.
void deleteNode(struct ListNode* node) {
        
        node->val = node->next->val;
        node->next = node->next->next;
        
}
*/
// solution 2 , a little better than solution 1.
void deleteNode(struct ListNode* node) {
        *node = *node->next;//I forgot the priority of operator * and operator -> 
}

 

[LeetCode笔记]-237-Delete Node in a Linklist

原文:http://www.cnblogs.com/xajhzdfbb/p/4841184.html

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