From be4e1c3406f556d0cd564ef14f9f2adfa682f5bc Mon Sep 17 00:00:00 2001 From: Sanskar-Dwivedi Date: Sat, 27 Jun 2026 12:29:34 +0530 Subject: [PATCH] Added solution for problem 0142 linked list cycle 2 in python --- python/0142-linked-list-cycle-II.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 python/0142-linked-list-cycle-II.py 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