diff --git a/python/0142-linked-list-cycle-II.py b/python/0142-linked-list-cycle-II.py new file mode 100644 index 000000000..e59020e15 --- /dev/null +++ b/python/0142-linked-list-cycle-II.py @@ -0,0 +1,12 @@ +class Solution(object): + def detectCycle(self, head): + slow=fast=head + while fast and fast.next: + slow,fast=slow.next,fast.next.next + if slow==fast: + break + else: + return None + while head!=slow: + head,slow =head.next,slow.next + return head \ No newline at end of file