pass 141 easy
This commit is contained in:
21
141-240525-pass/main.py
Normal file
21
141-240525-pass/main.py
Normal file
@@ -0,0 +1,21 @@
|
||||
# Definition for singly-linked list.
|
||||
class ListNode:
|
||||
def __init__(self, x):
|
||||
self.val = x
|
||||
self.next = None
|
||||
|
||||
# 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:
|
||||
cnt = 0
|
||||
if head == None: return False
|
||||
while cnt < 1e4+10:
|
||||
if head.next == None:
|
||||
return False
|
||||
head = head.next
|
||||
cnt += 1
|
||||
return True
|
Reference in New Issue
Block a user