```python class ListNode: """Definition for singly-linked list node.""" def __init__(self, val=0, next=None): self.val = val self.next = next def reverse_linked_list(head: ListNode) -> ListNode: """ Reverses a singly linked list and returns the new head. Args: head: The head node of the linked list. Returns: The new head node of the reversed linked list. """ prev = None current = head while current: next_node = current.next # Store the next node current.next = prev # Reverse the link prev = current # Move prev forward current = next_node # Move current forward return prev def list_to_array(head: ListNode) -> list: """Helper function to convert linked list to array for testing.""" result = [] current = head while current: result.append(current.val) current = current.next return result def array_to_list(arr: list) -> ListNode: """Helper function to convert array to linked list for testing.""" if not arr: return None head = ListNode(arr[0]) current = head for val in arr[1:]: current.next = ListNode(val) current = current.next return head ```