llllmz

导航

876. 链表的中间结点c

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* middleNode(struct ListNode* head) {
    struct ListNode* slow=head,*fast=head;
    while(fast&&fast->next){
        slow=slow->next;
        fast=fast->next->next;
    }
    return slow;
}

 

posted on 2024-03-20 17:06  神奇的萝卜丝  阅读(10)  评论(0)    收藏  举报