You are given the head of a singly linked list.
Your task is to determine if there is a cycle in this linked list.
Note that:
next pointers.Return true if a cycle is present, otherwise false.
1 → 0 → 1 → null
False
The linked list is 1 -> 0 -> 1 -> null. There is no cycle.
1 → 2 → 3
↑ ↓
← ← True
The linked list is 1 -> 2 -> 3 -> (back to node at index 1). There is a cycle.
None
False
The linked list empty. There is no cycle.
1 → 0 → 1 → null
False