Given the head of a singly linked list, reverse the linked list and return its updated head.
Constraints:
Let n be the number of nodes in a linked list.
- 1≤
n ≤500
- −5000≤
Node.value ≤5000
So far, you’ve probably brainstormed some approaches and have an idea of how to solve this problem. Let’s explore some of these approaches and figure out which one to follow based on considerations, such as time complexity and any implementation constraints.