
Given the head of a singly linked list, reverse the list in place and return the new head. Each node contains an integer value and a next pointer. If the list is empty or has one node, return it unchanged.
Example 1:
Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Explanation: The `next` pointers are reversed so the list order becomes the opposite.
Example 2:
Input: head = [1, 2]
Output: [2, 1]
Explanation: The second node becomes the new head after reversal.
0 <= number of nodes <= 5000-5000 <= node.val <= 5000head = [1, 2, 3, 4, 5]Output[5, 4, 3, 2, 1]WhyEach pointer is reversed, so the tail becomes the new head.head = [1, 2]Output[2, 1]WhyThe second node points to the first after reversal.0 <= number of nodes <= 5000-5000 <= node.val <= 5000The list is singly linkedThe solution should run in linear timedef reverse_linked_list(head):