【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;
}

 

上一篇:JDBC


下一篇:基于JDBC进行数据库的增删改查