Sort by

recency

|

999 Discussions

|

  • + 0 comments

    Solution in C

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

    }

  • + 0 comments

    i need to ask sth using javascript check condition using while(currentnode.next) always gave a runtime error bec the compiler can't read null but when i used just currentnode solved it

  • + 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);
    
    }