# Leetcode45：Intersection of Two Linked Lists

Write a program to find the node at which the intersection of two singly linked lists begins.

For example, the following two linked lists:

A:          a1 → a2
↘
c1 → c2 → c3
↗
B:     b1 → b2 → b3


begin to intersect at node c1.

Notes:

• If the two linked lists have no intersection at all, return null.
• The linked lists must retain their original structure after the function returns.
• You may assume there are no cycles anywhere in the entire linked structure.

• Your code should preferably run in O(n) time and use only O(1) memory.
/**
* struct ListNode {
*     int val;
*     ListNode *next;
*     ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
<span style="white-space:pre">	</span>int lenA = 0;
int lenB = 0;
{
lenA++;
}
{
lenB++;
}
int n;
if (lenA < lenB)
{
n = lenB - lenA;
for (int i = 0; i < n; i++)
{
}
}
else
{
n = lenA - lenB;
for (int i = 0; i < n; i++)
{
}
}

{
}

}
};

2016-01-24 09:26:28

#### 【LeetCode】Intersection of Two Linked Lists

2014-11-27 21:55:23

#### [Leetcode] #160 Intersection of Two Linked Lists

2017-02-11 09:44:18

#### 【LeetCode】160. Intersection of Two Linked Lists

2016-03-16 20:53:48

#### <LeetCode OJ> 160. Intersection of Two Linked Lists

2016-05-01 23:24:43

#### leetcode 160: Intersection of Two Linked Lists

2014-12-30 03:17:29

#### [leetcode]Intersection of Two Linked Lists　——　熟悉python

2014-12-11 11:41:03

#### LeetCode 160 — Intersection of Two Linked Lists（C++ Python）

2014-12-02 20:59:16

#### 160. Intersection of Two Linked Lists（python）

2016-09-18 21:38:02

#### LeetCode 160 ：Intersection of Two Linked Lists

2015-05-14 22:06:04