Given the head of a singly linked list, reverse it and return the new head.
Input: one line of space-separated integers — the list values in order (may be empty). Output: the reversed list's values, space-separated.
1 2 3 4 5
5 4 3 2 1
1 2
2 1
Run your code against the sample tests, or Submit to run the full suite.