Reverse Linked List
Easy
LC #206
in-place reversalpointersNot attempted yet
You're given the head of a singly linked list. Reverse
the list and return the new head.
Example 1
Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
Example 2
Input: head = [8,3]
Output: [3,8]
Example 3
Input: head = []
Output: []
Constraints
- 0 ≤ number of nodes ≤ 5 · 10⁴
- -10⁵ ≤ Node.val ≤ 10⁵
Can you do it in O(1) extra space?