Answers and Comments


User Avatar
Written by aleksin


Solution:

1. Find lenghts (L1 and L2) of both list -- O(n) + O(n) = O(n)
2. Take the difference d of the lengths -- O(1)
3. Make d steps in longer list -- O(n)
4. Step in both lists in parallel until links to next node match -- O(n)

total time complexity = O(n)


Saved Stories

Sponsored Categories