Share my code, help to improve it.

  • 1

    It cost me a few hours.

      ListNode *reverseBetween(ListNode *head, int m, int n) {
        if(head==NULL || m==n) return head;
        if(m==n) return head;
        int k=1;
        ListNode *pNode = head;
                pNode = pNode->next;
            pNode->next = reverse(pNode->next, n, k);
            return head;
            return reverse(pNode, n, --k);
    ListNode *reverse(ListNode *head, int n, int &k){
        if(k==n) return head;
        ListNode *newHead = reverse(head->next, n,k);
        ListNode *p = head->next;
        head->next = p->next;
        p->next = head;
        return newHead;

  • 0
    This post is deleted!

  • 0

    Wow, this is so complicated.

    How did you intuitively think of this?

Log in to reply

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