Share my 3 ms C solution, it's very clean and easy to understand

  • 6

    more codes see:

    struct ListNode* partition(struct ListNode* head, int x) {

    struct ListNode left,right;
    struct ListNode *left_cursor,*right_cursor;
    left_cursor = &left;
    right_cursor = &right;
        if(head->val < x){
            left_cursor->next = head;
            left_cursor = left_cursor->next;
            right_cursor->next = head;
            right_cursor = right_cursor->next;
        head = head->next;
    right_cursor->next = NULL;
    left_cursor->next =;


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.