【leetcode】143. 重排链表

void reorderList(struct ListNode* head){
    struct ListNode* arr[40000];
    struct ListNode* temp=(struct ListNode*)calloc(1,sizeof(struct ListNode));
    int pst=0;
    while(head){
        arr[pst++]=head;
        head=head->next;
    }
    for (int i=0; i<(pst+1)/2; i++){
        arr[i]->next=arr[pst-1-i];
        temp->next=arr[i];
        temp=arr[pst-1-i];
    }
    temp->next=NULL;
    return head;
}
void reorderList(struct ListNode* head){
    struct ListNode* arr[40000];
    struct ListNode* temp=(struct ListNode*)calloc(1,sizeof(struct ListNode));
    int pst=0;
    while(head){
        arr[pst++]=head;
        head=head->next;
    }
    for (int i=0; i<(pst+1)/2; i++){
        arr[i]->next=arr[pst-1-i];
        temp->next=arr[i];
        temp=arr[pst-1-i];
    }
    temp->next=NULL;
    return head;
}
原文地址:https://www.cnblogs.com/ganxiang/p/14173748.html