Linked List Reversal
Expert
data_structures
linked_lists
algorithms
Description
Reverse a singly linked list in place and return the new head of the list. You will be given the head of the list.
Examples
Example:
Input: Head -> 1 -> 2 -> 3 -> 4 -> null
Output: Head -> 4 -> 3 -> 2 -> 1 -> null
Explanation: The pointers are flipped, and the new head is the original tail.
Constraints
- Must reverse the list in place (O(1) extra space complexity, excluding the input nodes).
- Input is the head of the linked list.
Loading...
Test Case 1
Input: [1,2,3,4]
Output: [4,3,2,1]
Test Case 2
Input: [1]
Output: [1]
Test Case 3
Input: []
Output: []
