Skip to content

Bug Report for linked-list-cycle-detection #5418

@olegesan

Description

@olegesan

Bug Report for https://neetcode.io/problems/linked-list-cycle-detection

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

The problem description mentions that the list has at least 1 node in it. However, one of the tests that the solution runs against has an empty list.

1 <= Length of the list <= 1000.

code that highlights the bug

class Solution:
    def hasCycle(self, head: Optional[ListNode]) -> bool:
        output = False
        s, f = head,  head.next.next if head.next else None
        while f:
            if s == f:
                output = True
                break
            s = s.next
            f = f.next.next if f.next else None
        return output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions