141. Linked List Cycle
ε¨ Q202 ιη¨θΏηιΎε
θ΅θ·εΏ«ζ
’ζι
οΌηΈιε³θ―ζζη―γ
class Solution:
def hasCycle(self, head: ListNode) -> bool:
if not head: return False
slow = head
fast = head.next
while fast != slow:
if not fast or not fast.next: return False
else:
fast = fast.next.next
slow = slow.next
return True
Last updated
Was this helpful?