Reverse Linked List
Reverse the next pointers of a singly linked list and return its new head.
Example 1
head = [4,7,1][1,7,4]Explanation
Reverse 4->7->1 into 1->7->4, making 1 the new head.
Example 2
head = []nullExplanation
An empty list remains empty.
Example 3
head = [2][2]Explanation
A singleton has no link to reverse.
Constraints
- 0 <= number of nodes <= 5000
- Values are signed 32-bit integers
- Input is an acyclic list encoded as a value array
Function contract
reverseListArguments: listSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[4,7,1]