LeetCode 206 Reverse Linked List - Problem Statement

The problem

You're given the head of a singly linked list. Your task is to reverse it and return the new head.

For 1→2→3→4→5, you'd return 5→4→3→2→1. Every pointer now points backward.

Before coding, think: as you traverse the list, what information do you need to keep track of? You can't look backward in a singly linked list, so how do you remember where you came from?

Constraints: 0≤0 \le list length ≤5000\le 5000, node values from −5000-5000 to 50005000.