From 2d813325efaa7abeec886fb2185ef6152af9d376 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Sat, 27 Jun 2026 18:25:48 +0600 Subject: [PATCH] LeetCode #141: Linked List Cycle --- LeetCode/easy/has_cycle_141.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LeetCode/easy/has_cycle_141.py diff --git a/LeetCode/easy/has_cycle_141.py b/LeetCode/easy/has_cycle_141.py new file mode 100644 index 0000000..3dfb4cd --- /dev/null +++ b/LeetCode/easy/has_cycle_141.py @@ -0,0 +1,21 @@ +from typing import Optional + + +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + + +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + slow, fast = head, head + + while fast and fast.next: + slow = slow.next + fast = fast.next.next + + if fast == slow: + return True + + return False