C++ recursive solution


  • -1
    E
    ListNode* reverseList(ListNode* head) {
        if(head == nullptr || head->next == nullptr)
            return head;
        ListNode *p = head;
        head = reverseList(p->next);
        p->next->next = p;
        p->next = nullptr;
        return head;
    }

Log in to reply
 

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