• + 0 comments

    Here is my c++ solution, you can watch video explanation here : https://youtu.be/F4nGusqPIu0

    SinglyLinkedListNode* reverse(SinglyLinkedListNode* llist) {
        SinglyLinkedListNode* reverse = nullptr;
        while(llist != nullptr){
            SinglyLinkedListNode* newNode = new SinglyLinkedListNode(llist->data);
            newNode ->next = reverse;
            reverse = newNode;
            llist = llist->next;
        }
        return reverse;
    }