• + 0 comments

    c++ solution with recursive function

    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
        if (head1->data != head2->data) return false;
        if (head1->next == nullptr && head2->next == nullptr) return true;
        if (head1->next == nullptr || head2->next == nullptr) return false;
        return compare_lists(head1->next, head2->next);
    }