【leetcode】86. 分隔链表

struct ListNode* partition(struct ListNode* head, int x){
    struct ListNode* left=(struct ListNode*)calloc(sizeof(struct ListNode),1);
    struct ListNode* right=(struct ListNode*)calloc(sizeof(struct ListNode),1);
    struct ListNode* l=left, *r=right;
    while(head){
        if(head->val < x){
            l->next=head;
            l=head;
        }
        else{
            r->next=head;
            r=head;
        }
        head=head->next;
    }
    r->next=NULL;
    l->next=right->next;
    return left->next;
}
原文地址:https://www.cnblogs.com/ganxiang/p/14129339.html