Simple C / C++ SOLUTION :


  • 0
    M
        ListNode* reverseList(ListNode* head) 
        {
            if(head == NULL) return NULL;
            
            ListNode *p1 = head, *p2 = NULL, *p3 = NULL;
            
            while(p1)
            {
                p2 = p1->next;
                p1->next = p3;
                p3 = p1;
                p1 = p2;
            }
            
            return p3;
        }
    

Log in to reply
 

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