/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* middleNode(struct ListNode* head) {
struct ListNode*slow=head;
struct ListNode*fast=head;
while(fast/*偶判断*/&&fast->next/*奇判断*/){
slow=slow->next;
fast=fast->next->next;
}
return slow;
}
【数据结构】【链表代码】 链表的中间节点
最新推荐文章于 2024-11-10 22:49:00 发布