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.
Sorry about the terrible line wrapping. Hackerrank's comment system isn't quite perfect.
def CompareLists(headA, headB):
# Test cases expect a 0 or 1 instead of True/False
# return int(CompareListsRecursive(headA, headB))
return int(CompareListsIterative(headA, headB))
def CompareListsRecursive(headA, headB):
if headA is None or headB is None:
return headA == headB
return (headA.data == headB.data) and CompareListsRecursive(headA.next, headB.next)
def CompareListsIterative(headA, headB):
curA = headA
curB = headB
while ((curA is not None) and (curB is not None) and curA.data == curB.data):
curA = curA.next
curB = curB.next
if curA is None or curB is None:
return curA == curB
else:
return curA.data == curB.data
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 →
Sorry about the terrible line wrapping. Hackerrank's comment system isn't quite perfect.