diff --git a/leetcode/October LeetCoding Challenge/Start_Of_Linked_List_Cycle.py b/leetcode/October LeetCoding Challenge/Start_Of_Linked_List_Cycle.py new file mode 100644 index 0000000..9db8708 --- /dev/null +++ b/leetcode/October LeetCoding Challenge/Start_Of_Linked_List_Cycle.py @@ -0,0 +1,38 @@ +# Definition for singly-linked list. +# class ListNode: +# def __init__(self, x): +# self.val = x +# self.next = None + +class Solution: + def detectCycle(self, head: ListNode) -> ListNode: + try: + + slow = head.next + fast = head.next.next + + while slow != fast: + slow = slow.next + fast = fast.next.next + + else: + l = 1 + temp = slow.next + while temp!=slow: + temp = temp.next + l+=1 + + p1 = head + p2 = head + for i in range(l): + p2 = p2.next + + while p1!=p2: + p1 = p1.next + p2 = p2.next + + return p1 + + + except: + return None # No Cycle