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.
defcompare_lists(llist1:SinglyLinkedListNode,llist2:SinglyLinkedListNode)->bool:"""Iteratively check two linked lists for equality."""whilellist1andllist2andllist1.data==llist2.data:llist1=llist1.nextllist2=llist2.nextreturnllist1isNoneandllist2isNonedefcompare_lists(llist1:SinglyLinkedListNode,llist2:SinglyLinkedListNode)->bool:"""Recursively check two linked lists for equality."""matchllist1isNone,llist2isNone:caseFalse,False:return(compare_lists(llist1.next,llist2.next)ifllist1.data==llist2.dataelseFalse)caseTrue,True:returnTruecase_:returnFalse
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Compare two linked lists
You are viewing a single comment's thread. Return to all comments →
Python 3.10+