Given the head of a singly linked list, reverse the list and return the new head.
Example 1
Input1 -> 2 -> 3 -> 4 -> 5 -> null
Output5 -> 4 -> 3 -> 2 -> 1 -> null
Example 2
Input1 -> 2 -> null
Output2 -> 1 -> null
Example 3
Inputnull
Outputnull
Constraints
- 0 <= length of list <= 5000
- -5000 <= Node.val <= 5000
- Reverse the list in place; do not allocate new nodes.