Reverse a Linked List

Problem Reverse a singly linked list, both iteratively and recursively.

Input / Output

  • Input: head of a singly linked list.
  • Output: the head of the reversed list.

Constraints

  • 0 <= nodes <= 5000; the iterative version should use O(1) extra space.

Example

  • 1→2→3 → 3→2→1.
added …
LeaderboardSalaryAccount