题目描述
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)
输入格式
见题面
输出格式
见题面
样例输入
LinkedList1:1->2->3->4->5->6
LinkedList2:99->59->42->20
样例输出
Not identical