Problem
You get head, the first node of a linked list. A linked list is a chain of nodes, and each node links to the next node.
A linked list has a cycle when you can follow the next links from a node and return to the same node. Return true if the list has a cycle, and false if it does not.
The input shows the values of the nodes and an integer pos. The last node links to the node at index pos. If pos is -1, the list has no cycle. Your function gets only head, not pos.
Example 1
- Input:
- head = [5,1,8,3], pos = 2
- Output:
- true
- Explanation:
- The last node links to the node at index 2, which has the value 8.
Example 2
- Input:
- head = [6,4], pos = -1
- Output:
- false
- Explanation:
- The last node links to no node, so the list has no cycle.
Example 3
- Input:
- head = [2], pos = 0
- Output:
- true
- Explanation:
- The only node links to itself.
Constraints
- The number of nodes in the list is in the range [0, 10^4].
- -10^5 <= Node.val <= 10^5
- pos is -1 or a valid index in the linked list.
Follow-up
Can you solve it with O(1) extra memory?
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Happy Number
Coding · Floyd's Cycle Finding Algorithm · Hash Table · Math
- Palindrome Linked List
Coding · Linked List · Recursion · Stack
- Copy List with Random Pointer
Coding · Hash Table · Linked List
- All O`one Data Structure
Coding · Design · Doubly-Linked List · Hash Table
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 141. Linked List Cycle
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 2 records
Amazon
Linked List Cycle
Reported date not specified · Source window: 30d
Source snapshot: Oct 20, 2026
Source frequency score: 61.7. This is not an interview probability.
View sourceNVIDIA
Linked List Cycle
Reported date not specified · Source window: 6mo
Source snapshot: Oct 20, 2026
Source frequency score: 73.7. This is not an interview probability.
View source