Skip to content

Commit 20962c4

Browse files
author
sangbeenmoon
committed
solved linked-list-cycle.
1 parent 0b9dc57 commit 20962c4

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

linked-list-cycle/sangbeenmoon.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Definition for singly-linked list.
2+
class ListNode:
3+
def __init__(self, x):
4+
self.val = x
5+
self.next = None
6+
7+
class Solution:
8+
def hasCycle(self, head: Optional[ListNode]) -> bool:
9+
MM = 10001
10+
cnt = 0
11+
cur = head
12+
while cur != None:
13+
cnt += 1
14+
if cnt > MM:
15+
return True
16+
cur = cur.next
17+
18+
return False

0 commit comments

Comments
 (0)