diff --git a/linked-list-cycle/sangbeenmoon.py b/linked-list-cycle/sangbeenmoon.py new file mode 100644 index 0000000000..3e3a24c7df --- /dev/null +++ b/linked-list-cycle/sangbeenmoon.py @@ -0,0 +1,18 @@ +# Definition for singly-linked list. +class ListNode: + def __init__(self, x): + self.val = x + self.next = None + +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + MM = 10001 + cnt = 0 + cur = head + while cur: + cnt += 1 + if cnt > MM: + return True + cur = cur.next + + return False