We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Compare two linked lists
Compare two linked lists
+ 0 comments Here is the solution of Compare two linked lists Click Here
+ 0 comments if(head1==NULL && head2!=NULL){ return false; } else if(head1!=NULL && head2==NULL){ return false; } else if(head1== NULL && head2== NULL){ return true; } while(head1!=NULL && head2!=NULL){ if(head1->data!=head2->data){ return false; } head1=head1->next; head2=head2->next; } if(head1==NULL && head2!=NULL){ return false; } else if(head1!=NULL && head2==NULL){ return false; } else{ return true; }
+ 0 comments All test case passed
static boolean compareLists(SinglyLinkedListNode head1, SinglyLinkedListNode head2) {
boolean flag = true; while (head1 != null && head2 != null){ if(head1.data != head2.data){ flag = false; break; } head1 = head1.next; head2 = head2.next; } if(flag == false || head1 != null || head2 != null){ return false; } return true; }
+ 0 comments The TypeScript language option seems to be missing the compare_lists function described in the problem statement; the same is true for some of the subsequent challenges.
+ 0 comments bool compare_lists(SinglyLinkedListNode* head1, SinglyLinkedListNode* head2) { if (head1 == NULL && head2 == NULL) { return 1; } else if (head1 == NULL || head2 == NULL) { return 0; } if (head1->data == head2->data) { return compare_lists(head1->next, head2->next); } else { return 0; } }
Load more conversations
Sort 954 Discussions, By:
Please Login in order to post a comment