Reverse a Linked List / Detect Cycle
Problem Reverse a singly linked list, and separately detect whether a list contains a cycle.
Input / Output
- Input: head of a singly linked list.
- Output: the new head after reversal; and a boolean for whether a cycle exists.
Constraints
- 0 <= nodes <= 10^4; do both in O(1) extra space.
Example
- 1→2→3 reverses to 3→2→1. A list whose tail points back to node 2 has a cycle.
added …