Given two Singly Linked List of N and M nodes respectively. The task is to check whether two linked lists are identical or not. 
Two Linked Lists are identical when they have same data and with same arrangement too.
Example 1:
Input:
LinkedList1: 1->2->3->4->5->6
LinkedList2: 99->59->42->20
Output: Not identical 
Example 2:
Input:
LinkedList1: 1->2->3->4->5
LinkedList2: 1->2->3->4->5
Output: Identical
 
Your Task:
The task is to complete the function areIdentical() which takes the head of both linked lists as arguments and returns True or False.
Constraints:
1 <= N <= 10^{3}
Expected Time Complexity : O(N)
Expected Auxilliary Space : O(1)

Difficulty: EASY
Tags: Data structures
Skill types: Data structures
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)

Starter code:
# your task is to complete this function
# function should return true/1 if both
# are identical else return false/0
'''
# Node Class    
class node:
    def __init__(self, val):
        self.data = val
        self.next = None
        
'''

#Function to check whether two linked lists are identical or not.
def areIdentical(head1, head2):
    # Code here

Solutions:
def areIdentical(head1, head2):
	(res1, res2) = (head1, head2)
	while res1 != None and res2 != None:
		if res1.data != res2.data:
			return False
		res1 = res1.next
		res2 = res2.next
	return True


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


def areIdentical(head1, head2):
	while head1 is not None and head2 is not None:
		result = 1
		if head1.data != head2.data:
			result = 0
			break
		head1 = head1.next
		head2 = head2.next
	return result


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


def areIdentical(head1, head2):
	h1 = head1
	h2 = head2
	p = []
	q = []
	while h1.next != None:
		h1 = h1.next
		p.append(h1.data)
	p.append(h1.data)
	while h2.next != None:
		h2 = h2.next
		q.append(h2.data)
	q.append(h2.data)
	if p == q:
		return True
	else:
		return False


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


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


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


def areIdentical(head1, head2):
	temp1 = head1
	temp2 = head2
	while temp1 and temp2:
		if temp1.data != temp2.data:
			return 0
		temp1 = temp1.next
		temp2 = temp2.next
	return 1


def areIdentical(head1, head2):
	(tmp1, tmp2) = (head1, head2)
	while tmp1 != None and tmp2 != None:
		if tmp1 == None and tmp2 != None or (tmp2 == None and tmp1 != None) or tmp1.data != tmp2.data:
			return False
		tmp1 = tmp1.next
		tmp2 = tmp2.next
	return True


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


def areIdentical(head1, head2):
	(dummy1, dummy2) = (head1, head2)
	while dummy1 and dummy2:
		if dummy1.data != dummy2.data:
			return False
		dummy1 = dummy1.next
		dummy2 = dummy2.next
	if dummy1 is None and dummy2 is None:
		return True
	return False


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


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


def areIdentical(head1, head2):
	curr1 = head1
	curr2 = head2
	while curr1 != None and curr2 != None:
		if curr1.data != curr2.data:
			return False
		curr1 = curr1.next
		curr2 = curr2.next
	if curr1 != None or curr2 != None:
		return False
	return True


def areIdentical(head1, head2):
	t1 = head1
	t2 = head2
	while t1 and t2:
		if t1.data == t2.data:
			t1 = t1.next
			t2 = t2.next
			continue
		else:
			return False
	if t1 == t2 == None:
		return True
	else:
		return False


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


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


def areIdentical(head1, head2):
	while head1.next:
		if head1.data == head2.data:
			head1 = head1.next
			head2 = head2.next
		else:
			break
	if head1.data == head2.data:
		return True
	return False


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


def areIdentical(head1, head2):
	curr1 = head1
	curr2 = head2
	if head1 == None and head2 == None:
		return 1
	while curr1 != None and curr2 != None:
		if curr1.data != curr2.data:
			return 0
		if (curr1.next == None or curr2.next == None) and curr1.next != curr2.next:
			return 0
		curr1 = curr1.next
		curr2 = curr2.next
	return 1


def areIdentical(head1, head2):
	a = []
	b = []
	while head1 != None:
		a.append(head1.data)
		head1 = head1.next
	while head2 != None:
		b.append(head2.data)
		head2 = head2.next
	if a == b:
		return True
	else:
		return False


def areIdentical(head1, head2):
	lis1 = []
	lis2 = []
	while head1.next != None:
		lis1.append(head1.data)
		head1 = head1.next
	lis1.append(head1.data)
	while head2.next != None:
		lis2.append(head2.data)
		head2 = head2.next
	lis2.append(head2.data)
	if lis1 == lis2:
		return 1
	else:
		return 0


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


def areIdentical(head1, head2):
	c1 = head1
	c2 = head2
	while c1 != None and c2 != None:
		if c1.data != c2.data:
			return 0
		c1 = c1.next
		c2 = c2.next
	return 1


def areIdentical(head1, head2):
	p = head1
	q = head2
	while p and q:
		if p.data == q.data:
			p = p.next
			q = q.next
		else:
			return 0
	return 1


def areIdentical(head1, head2):
	temp1 = head1
	temp2 = head2
	len1 = 0
	len2 = 0
	is_identical = True
	while head1:
		len1 = len1 + 1
		head1 = head1.next
	while head2:
		len2 = len2 + 1
		head2 = head2.next
	if len1 != len2:
		return False
	else:
		while temp1 and temp2:
			if temp1.data != temp2.data:
				is_identical = False
			temp1 = temp1.next
			temp2 = temp2.next
		if not is_identical:
			return False
		if is_identical:
			return True


def areIdentical(head1, head2):
	a = head1
	b = head2
	while a and b:
		if a.data != b.data:
			return False
		a = a.next
		b = b.next
	return a == None and b == None


def areIdentical(head1, head2):
	c1 = 1
	c2 = 1
	temp1 = head1
	temp2 = head2
	while temp1 != None:
		c1 += 1
		temp1 = temp1.next
	while temp2 != None:
		c2 += 1
		temp2 = temp2.next
	if c1 != c2:
		return False
	elif c1 == c2:
		temp1 = head1
		temp2 = head2
		while temp1 != None and temp2 != None:
			if temp1.data != temp2.data:
				return False
			temp1 = temp1.next
			temp2 = temp2.next
	return True


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


def areIdentical(head1, head2):
	if head1.data != head2.data:
		return False
	curr1 = head1
	curr2 = head2
	while 1:
		if curr1.next != None:
			if curr2.next != None:
				if curr1.data != curr2.data:
					return False
			else:
				return False
		else:
			break
		curr1 = curr1.next
		curr2 = curr2.next
	if curr2.next != None:
		return False
	elif curr1.data != curr2.data:
		return False
	return True


class Node:

	def __init__(self, data):
		self.data = data
		self.next = None

def areIdentical(head1, head2):
	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):
	(l1, l2) = ([], [])
	while head1 != None:
		l1.append(head1.data)
		head1 = head1.next
	while head2 != None:
		l2.append(head2.data)
		head2 = head2.next
	if l1 == l2:
		return True
	else:
		return False


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


def areIdentical(head1, head2):
	first = head1
	second = head2
	if head1 == None or head2 == None:
		return False
	elif head1 == None and head2 == None:
		return True
	while first and second:
		if first.data == second.data:
			first = first.next
			second = second.next
		else:
			return False
	return True


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


def areIdentical(head1, head2):
	l1 = []
	l2 = []
	while head1:
		l1.append(head1.data)
		head1 = head1.next
	while head2:
		l2.append(head2.data)
		head2 = head2.next
	return l1 == l2


def areIdentical(head1, head2):
	a = []
	b = []
	temp1 = head1
	temp2 = head2
	while temp1 != None:
		a += [temp1.data]
		temp1 = temp1.next
	while temp2 != None:
		b += [temp2.data]
		temp2 = temp2.next
	if a == b:
		return True
	else:
		return False


def areIdentical(head1, head2):
	t1 = head1
	t2 = head2
	while t1 != None or t2 != None:
		if t1.data == t2.data:
			t1 = t1.next
			t2 = t2.next
		else:
			return False
	if t1 != None or t2 != None:
		return False
	return True


def areIdentical(head1, head2):
	current1 = head1
	current2 = head2
	while current1 and current2:
		if current1.data == current2.data:
			(current1, current2) = (current1.next, current2.next)
		else:
			return False
	return True


def length(head):
	k = 0
	while head != None:
		k += 1
		head = head.next
	return k

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


def areIdentical(head1, head2):
	t = head1
	t1 = head2
	while t != None and t1 != None:
		if t.data != t1.data:
			return 0
		t = t.next
		t1 = t1.next
	return 1


def areIdentical(head1, head2):
	flag = True
	while head1 != None and head2 != None:
		if head1.data != head2.data:
			flag = False
		head1 = head1.next
		head2 = head2.next
	if flag:
		return 1
	else:
		return 0


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


def areIdentical(h1, h2):
	t1 = h1
	t2 = h2
	while t1 and t2:
		if t1.data != t2.data:
			return False
		t1 = t1.next
		t2 = t2.next
	if t1 or t2:
		return False
	return True


def areIdentical(head1, head2):
	if head1 == None and head2 == None:
		return True
	if head1 != None and head2 == None or (head2 != None and head1 == None):
		return False
	node1 = head1
	node2 = head2
	while node1 != None and node2 != None:
		if node1.data != node2.data:
			return False
		node1 = node1.next
		node2 = node2.next
	if node1 != None or node2 != None:
		return False
	else:
		return True


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


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


def areIdentical(head1, head2):
	temp1 = head1
	temp2 = head2
	(count1, count2) = (0, 0)
	while temp1:
		count1 += 1
		temp1 = temp1.next
	while temp2:
		count2 += 1
		temp2 = temp2.next
	if count1 != count2:
		return False
	temp1 = head1
	temp2 = head2
	while temp1 != temp2:
		if temp1.data != temp2.data:
			return False
		temp1 = temp1.next
		temp2 = temp2.next
	return True


def areIdentical(head1, head2):
	if head1 == None and head2 == None:
		return 1
	if head2 == None or head1 == None:
		return 0
	while head1 != None and head2 != None:
		if head1.data != head2.data:
			return 0
		head1 = head1.next
		head2 = head2.next
	if head1 == None and head2 == None:
		return 1
	else:
		return 0


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


def areIdentical(head1, head2):
	a = head1
	(list1, list2) = ([], [])
	b = head2
	while a is not None:
		list1.append(a.data)
		a = a.next
	while b is not None:
		list2.append(b.data)
		b = b.next
	if len(list1) != len(list2):
		return False
	else:
		for i in range(len(list1)):
			if list1[i] == list2[i]:
				continue
			else:
				return False
				break
		return True


def areIdentical(head1, head2):
	if head1 and head2:
		if head1.data != head2.data:
			return False
		else:
			return areIdentical(head1.next, head2.next)
	return head1 is None and head2 is None