Skip to content

Commit 1493d6a

Browse files
committed
IntersectionOfTwoLinkedLists160
1 parent f2b8455 commit 1493d6a

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/IntersectionOfTwoLinkedLists160.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
6868

6969
/**
7070
* https://leetcode.com/problems/intersection-of-two-linked-lists/discuss/49785/Java-solution-without-knowing-the-difference-in-len!
71+
*
72+
* You can prove that: say A length = a + c, B length = b + c, after
73+
* switching pointer, pointer A will move another b + c steps, pointer B
74+
* will move a + c more steps, since a + c + b + c = b + c + a + c, it
75+
* does not matter what value c is. Pointer A and B must meet after
76+
* a + c + b (b + c + a) steps. If c == 0, they meet at NULL.
77+
*
7178
*/
7279
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
7380
//boundary check

0 commit comments

Comments
 (0)