def areIdentical(head1, head2): if not head1 and not head2: return True if not head1 and head2: return False if head1 and not head2: return False while head1 and head2: if head1.data != head2.data: return False head1 = head1.next head2 = head2.next if not head1 and not head2: return True return False
def areIdentical(head1, head2):
if not head1 and not head2:
return True
if not head1 and head2:
return False
if head1 and not head2:
return False
while head1 and head2:
if head1.data != head2.data:
return False
head1 = head1.next
head2 = head2.next
if not head1 and not head2:
return True
return False