# 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:

1. If the two linked lists have no intersection at all, return null.
The linked lists must retain their original structure after the
function returns.
2. You may assume there are no cycles anywhere in the entire linked structure.
3. Your code should preferably run in O(n) time and use only O(1) memory.

JAVA代码：

public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

// 解题思路：首先，将两个数组反转，然后，依次比较，找到第一个不一样的链表节点，输出第一个不一样的节点的上一节点即可。
ListNode interNode;
int num=0;             //用于计算非交叉的节点数
{
return null;
}
{
return null;
}else{

{
}
{
num++;
}
for(int i=0;i<num;i++)
{
}

}
}
public ListNode reverseList(ListNode head)  //链表反转方法
{
ListNode temp;
while(current.next!=null)
{
temp=current.next;
current.next=temp.next;
}
}
}

百思不得其解，其实，我离成功只差一步了，哈哈哈！！！！可以想到反转链表计算其不一样的链表节点数，为啥子没想到，A链表-B链表=num,只要B链表遍历时的步数比A链表多num步，就可以依次同步遍历，直到寻找到相同的节点为止！！！

JAVA代码：
/**

 * Definition for singly-linked list.
* public class ListNode {
*     int val;
*     ListNode next;
*     ListNode(int x) {
*         val = x;
*         next = null;
*     }
* }
*/
public class Solution {
public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
int i=1,
j=1;
{
return null;
}
{
i++;
}
{
j++;
}
{
return null;  //最后一个节点不相等，则无交叉节点
}
int num=i-j;
if(num>0)        //A链表数目多时，先遍历多出的节点数目
{
while(num>0)
{
num--;
}
}{
num=Math.abs(num); //B链表数目多时，遍历多出的节点数目
while(num>0)
{
num--;
}
}
{
}

}

}


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

2014-12-30 03:17:29

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

2014-11-27 21:55:23

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

2014-12-11 11:41:03

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

2016-09-18 21:38:02

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

2014-12-02 20:59:16

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

2015-05-14 22:06:04

2015-09-14 10:16:22

#### 【leetcode 两个链表的交集点】Intersection of Two Linked Lists

2014-11-28 00:15:09

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

2015-04-11 18:56:52

#### Leetcode_160_Intersection of Two Linked Lists

2014-11-29 10:37:20