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

237. Delete Node in a Linked List

时间:2018-05-24 18:12:19      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:sync   col   static   ret   nod   直接   div   指针   ==   

 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 static int wing=[]()
10 {
11     std::ios::sync_with_stdio(false);
12     cin.tie(NULL);
13     return 0;
14 }();
15 
16 class Solution 
17 {
18 public:
19     void deleteNode(ListNode* node) 
20     {
21         if(node==NULL)
22             return;
23         ListNode *next_node=node->next;
24         if(next_node!=NULL)
25         {
26             node->val=next_node->val;
27             node->next=next_node->next;
28         }
29     }
30 };

在只能访问待删除节点的情况下删除一个链表的节点,直接把待删除节点的下一个节点值放在待删除节点,然后修改指针,跳过下一个节点即可。

237. Delete Node in a Linked List

标签:sync   col   static   ret   nod   直接   div   指针   ==   

原文地址:https://www.cnblogs.com/zhuangbijingdeboke/p/9083735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!