首页 > 其他 > 详细

876. 链表的中间结点

时间:2021-06-16 16:44:00      阅读:19      评论:0      收藏:0      [点我收藏+]
 1 /**
 2  * Definition for singly-linked list.
 3  * struct ListNode {
 4  *     int val;
 5  *     struct ListNode *next;
 6  * };
 7  */
 8 
 9 
10 struct ListNode* middleNode(struct ListNode* head){
11     int count = 0;
12     struct ListNode *p = head;
13     while(p)
14     {
15         count++;
16         p=p->next;
17     }
18 
19     int index = count/2+1;
20     count = 0;
21     while(head)
22     {
23         count++;
24         if(count==index){
25             break;
26         }
27 
28         head = head->next;
29     }
30 
31     return head;
32 
33 
34 }

 

876. 链表的中间结点

原文:https://www.cnblogs.com/Knightl8/p/14889800.html

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