This takes O(M+N) time and O(1) space, where M and N are the total length of the linked lists. Maybe inefficient if the common part is very long (i.e. M,N >> m,n)
- Traverse the two linked list to find M and N.
- Get back to the heads, then traverse |M − N| nodes on the longer list.
- Now walk in lock step and compare the nodes until you found the common ones.
Edit: See more here.