In Snowflake-style coding interviews, a common data structure task is to reverse a singly linked list in place. Write a function that takes the head of a singly linked list and returns the head of the reversed list.
head, the first node of a singly linked list, or null for an empty list.val and next.Example 1
head = [1, 2, 3, 4, 5][5, 4, 3, 2, 1]next pointer is reversed, so the tail becomes the new head.Example 2
head = [7][7]Example 3
head = [][]0 <= number of nodes <= 5000-10^4 <= Node.val <= 10^4O(n) timeO(1) extra space for the main solution