# Python代码

"""
Definition of ListNode
class ListNode(object):

def __init__(self, val, next=None):
self.val = val
self.next = next
"""
class Solution:
"""
@return: The node where the cycle begins.
if there is no cycle, return null
"""
return None

while fast != None and fast.next != None:
slow = slow.next
fast = fast.next.next
if slow == fast:
break

if fast != None and fast == slow:
while fast != slow:
slow = slow.next
fast = fast.next
return fast

return None

GitHub -- Python代码

# C++代码

/**
103 带环链表 II

*/

/**
* Definition of ListNode
* class ListNode {
* public:
*     int val;
*     ListNode *next;
*     ListNode(int val) {
*         this->val = val;
*         this->next = NULL;
*     }
* }
*/
class Solution {
public:
/**
* @return: The node where the cycle begins.
*           if there is no cycle, return null
*/
{
return NULL;
}//if

while(fast && fast->next)
{
slow = slow->next;
fast = fast->next->next;
if(slow == fast)
{
break;
}//if
}//while

if(fast && fast == slow)
{
while(fast != slow)
{
fast = fast->next;
slow = slow->next;
}//while

return fast;
}//if
return NULL;

}
};


GitHub -- C++代码

#### *[Lintcode]带环链表 II

2017-02-07 11:40:12

#### 单链表面试题系列之带环链表的入口点

2016-06-12 19:46:18

#### lintcode-103

2015-09-02 19:47:30

#### 带环链表 II

2018-01-19 20:17:17

#### 带环链表返回起始节点

2017-08-19 08:56:55

2014-04-12 20:05:52

#### 如何找到带环链表的入口节点？

2016-10-24 02:07:43

#### lintcode-带环链表-102

2015-09-16 17:52:23

#### LintCode（102） 带环链表

2016-05-31 20:46:41

#### 带环链表

2015-09-12 23:02:47

## 不良信息举报

LintCode（103）带环链表 II