bumpsoo 2025-06-09 14:53:03 +00:00
parent b96b438b8a
commit 74ea899d2c

23
easy/linked_list_cycle.py Normal file
View file

@ -0,0 +1,23 @@
# https://leetcode.com/problems/linked-list-cycle
from typing import Optional
class ListNode:
val: int
next: Optional["ListNode"]
class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
first: Optional[ListNode] = head
second: Optional[ListNode] = head
while first is not None and \
first.next is not None and \
second is not None:
first = first.next.next
second = second.next
if first == second:
return True
return False