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

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

 

posted on 2015-09-26 19:46  Asymmetric  阅读(135)  评论(0编辑  收藏  举报