My solution for reverse Linked list


  • 1
    Y
    struct ListNode* reverseList(struct ListNode* head) {
        if(head == NULL||head->next==NULL) return head;
        struct ListNode* p1 = head, *p2=p1->next, *p3=p2;
        while(p2 != NULL){
            p3 = p2->next; p2->next = p1; p1=p2;p2=p3;
        }
        head->next=NULL;
        head = p1;
        return head;
    }

Log in to reply
 

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