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

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

时间:2015-09-26 21:07:29      阅读:155      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!