Typical leetcode linked list questions
Implement the standard linked-list reversal task. Given the head of a singly linked list, reverse the links in place and return the new head.
The input is a ListNode reference, where each node has val and next fields. Return a ListNode reference representing the reversed list. The list may be empty. Example: [1, 2, 3] becomes [3, 2, 1].
def reverse_list(head):