#C9882. Reverse a Singly Linked List
Reverse a Singly Linked List
Reverse a Singly Linked List
You are given a singly linked list. Your task is to reverse the linked list and output the node values in the new order. The reversal must be performed in place with \(O(n)\) time complexity and \(O(1)\) extra space.
The linked list is represented by a sequence of integers. You need to first build the linked list from the input, then reverse it using pointer manipulation, and finally output the reversed list.
inputFormat
The first line contains an integer \(n\) representing the number of nodes in the linked list. If \(n > 0\), the second line contains \(n\) space-separated integers corresponding to the node values in order.
outputFormat
Output a single line with the \(n\) space-separated integers representing the values of the reversed linked list. If the list is empty, output nothing.
## sample0