8mm simple C++ recursive solution

  • 1
    ListNode* reverseList(ListNode* head) {
                return head;
            if(head->next->next == NULL){
                ListNode* tmp = head->next;
                tmp->next = head;
                head->next = NULL;
                return tmp;
            ListNode* newhead = reverseList(head->next);
            head->next->next = head;
            head->next = NULL;
            return newhead;

Log in to reply

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