237. Delete Node in a Linked List 删除链表中的节点

237. Delete Node in a Linked List


 

 

思路:用node节点的下一个节点来覆盖node节点,然后删除node的下一个节点

 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     ListNode *next;
 6  *     ListNode(int x) : val(x), next(NULL) {}
 7  * };
 8  */
 9 class Solution {
10 public:
11     void deleteNode(ListNode* node) {
12         ListNode* pNext = node->next;
13         node->val = pNext->val;
14         node->next = pNext->next;
15         
16         delete pNext;
17         pNext = nullptr;
18     }
19 };

 

posted @ 2017-10-24 16:06  绿宝宝怪  阅读(120)  评论(0编辑  收藏  举报
#site_nav_under,#ad_under_post_holder,#under_post_news,#google_ad_c2,#under_post_kb{ width:0; height:0; display:none; overflow:hidden; }