In a Syneos Health workflow, a patient processing queue may be represented as a singly linked list. Write a function that reverses the linked list in place and returns the new head.
You are given the head of a singly linked list, where each node contains a value and a pointer to the next node. Return the head of the reversed list.
head, the first node of a singly linked list, or None for an empty listExample 1
head = [1, 2, 3, 4, 5][5, 4, 3, 2, 1]next pointer is redirected so the list order is reversed.Example 2
head = [7][7]0 <= number of nodes <= 10^5-10^9 <= node.val <= 10^9O(n) time and O(1) extra space