# LeetCode -- Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null.

Note: Do not modify the linked list.

Can you solve it without using extra space?

1. 使用快慢指针的方法找到环的位置。
2. 如果找到了环，慢指针回到起点，快慢指针每次各走一步，下一次相遇的位置就是环的起点。

/**
* public class ListNode {
*     public int val;
*     public ListNode next;
*     public ListNode(int x) {
*         val = x;
*         next = null;
*     }
* }
*/
public class Solution {
{
return null;
}

var found = false;
while(p != null && q != null && q.next != null && !found){
var t = q;
p = p.next;
q = q.next.next;
if(ReferenceEquals(p,q)){
found = true;
}
}

if(!found){
return null;
}

// p start from head again
// and q standing where it is
// next time they meet point is where cycle starts from
while(!ReferenceEquals(p, q)){
p = p.next;
q = q.next;
}

return q;
}
}

• 本文已收录于以下专栏：

### 相关文章推荐

COPY FROM： 比I麻烦点的就是找到循环开始点TAT I只是判断是否循环。要求不使用额外空间（不然hash就可以了 按I的思路，我们又慢指针S和快指针F。。。F走两...

## [leetcode] 142. Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Not...

## LeetCode 142 Linked List Cycle II

Given a linked list, return the node where the cycle begins. If there is no cycle, return null. N...

## [LeetCode] Linked List Cycle II, Solution

Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Fol...

## [LeetCode] 142. Linked List Cycle II java

/**142. Linked List Cycle II * @param head * @return */ public ListNode detectCy...

举报原因： 您举报文章：LeetCode -- Linked List Cycle II 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)