思路
- use two nested loops
- Use reverse list
- Met a problem. We have to rebuilt two new lists to reverse them, but the ListNode cannot be the ones in original lists.
- Virtual Cycles
- However, if no intersection, the while loop will be endless
- Till then, I notice that the intersection part will always be the latter part towards the tail of both lists, so we can check the ( len - k) th node to see if that’s the beginning of the intersection
- But, as the random length before the intersection part, it is hard to say how long will move one-by-one for the other list
- Till now, I missed somthing, Actually there is one more property we can notice, is that The intersection part will be covered by both lists. We can start to check from the node that both lists have the same number of remaining nodes!
- Correct thinking https://discuss.leetcode.com/topic/33291/recommend-for-beginners-clean-c-implementation-with-detailed-explaination
- From the above solution, Knowing the length of each list is very complicated.
- But our goal is to make two pointers pA and pB to stop at the node that
the number of remaining nodes == length of shorter list
- We can traverse both list, suppose listA.length < listB.length. After pA reaches the end of listA, pA will go to headB. So that when pB traversed to the end, pA stopped at the node that remaining number of notes are same as length of listA.
- Finish this by one method. A lot of bugs recorded in comments