Skip to content

Commit a075497

Browse files
committed
feat: week9 - linked list cycle
1 parent f548cf4 commit a075497

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

linked-list-cycle/Seoya0512.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def hasCycle(self, head: Optional[ListNode]) -> bool:
3+
cycle_set = set()
4+
while head:
5+
if head in cycle_set:
6+
return True
7+
cycle_set.add(head)
8+
head = head.next
9+
return False
10+

0 commit comments

Comments
 (0)