I'm just new to these problems. First thought is that you reverse the two lists and then iterate from the end until you have two different nodes. Then reserve them back in order not to change the structures. I know this is not a good solution, but I don't know why I exceeded memory limit...When I reverse the list, I use three pointers, prev, cur, next. Think it is still O(1) space.
Can anyone help with this question??
If you see the Memory Limit Exceeded error without manually allocating spaces, then it is very possible that you have modified the original list structure so a loop occurs somewhere, thus generating a list of infinite length.
Unfortunately, your solution will not work for this problem. Note that each node only has one next pointer, so one node can never point to two descendents. What you hope is that, when you reverse the entire structure, then the intersection node will become a node that points to two different branches, right? As I have already shown you, this is not feasible.
You may read other solutions posted here.
I tried and pass on IDE, but got WA on OJ, could you help me see what's wrong?Thank you!