Sort by

recency

|

997 Discussions

|

  • + 0 comments

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

    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
        while(head1 != nullptr && head2 !=nullptr) {
            if(head1->data != head2->data) return false;
            head1 = head1 ->next;
            head2 = head2 ->next;
        }
        return head2 == head1;
    }
    
  • + 0 comments

    simple python solution:

    def compare_lists(llist1, llist2):    
        while llist1 and llist2:
            if llist1.data != llist2.data:
                return False
            
            llist1 = llist1.next
            llist2 = llist2.next
            
        if (not llist1 and llist2) or (llist1 and not llist2):
            return False
            
        return True
    
  • + 0 comments

    Recursive C++ Linked List Comparison

    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
        if (head1 == NULL && head2 == NULL) {
            return true;
        }
        if (head1 == NULL || head2 == NULL) {
            return false;
        }
        
        return (head1->data == head2->data) && compare_lists(head1->next, head2->next);
    
    }
    
  • + 0 comments
    def compare_lists(llist1, llist2):
        while llist1 or llist2:
            if llist1.data == llist2.data and (llist1_count == llist2_count):
                llist1 = llist1.next
                llist2 = llist2.next
            else:
                return 0
        return 1
    
  • + 0 comments
    bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) {
        while(head1 && head2 && head1->data == head2->data){
            head1 = head1->next;
            head2 = head2->next;
        }
        if(head1 || head2){
            return false;
        }
        return true;
    }