Skip to content

LC 0141 [E] Linked List Cycle

Code with Senpai edited this page Mar 17, 2021 · 1 revision
class Solution:
    def hasCycle(self, head: ListNode) -> bool:
        fast = slow = head
        
        while fast and fast.next:
            fast = fast.next.next
            slow = slow.next
            if fast == slow:
                return True
            
        return False
Clone this wiki locally