My Simple C Solution


  • 0
    R
    struct ListNode* reverseList(struct ListNode* head) {
        struct ListNode *a, *b;
        if (head == NULL) return NULL;
        else if(head->next == NULL) return head;
        a = head;
        b = head->next;
        a->next = NULL;
        while(b != NULL) {
            a = b;
            b = b->next;
            a->next = head;
            head = a;
        }
        return head;
    }
    

Log in to reply
 

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