A simple non-recur c++ solution


  • 0
    B
    ListNode *reverseList( ListNode *head )
    {
        ListNode *p,*q;
        if ( head == NULL )
            return NULL;
        p = head->next;
        head->next = NULL;
        while ( p )
        {
            q = p->next;
            p->next = head;
            head = p;
            p = q;
        }
        return head;
    }

Log in to reply
 

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