Any error in my code?


  • 0
    L
    class Solution {
    public:
        ListNode *sortList(ListNode *head) {
            return qsort(head, NULL);
        }
        
        ListNode *qsort(ListNode *head, ListNode *tail = NULL)
        {
            if (head == tail || head == tail->next)
                return head;
            ListNode *i = head, *j;
            for (j = head->next; j != tail; j = j->next)
            {
                if (j->val < head->val)
                {
                    i = i->next;
                    swap(i->val, j->val);
                }
            }
            swap(head->val, i->val);
            
            qsort(head, i);
            qsort(i->next, tail);
            return head;
        }
        void swap(int &a, int &b)
        {
            int tmp = a;
            a = b;
            b = tmp;
        }
    };
    

    Any error in my code, test on my pc is ok. but get an error "RunTime Error" on oj.


Log in to reply
 

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