Reverse a Doubly Linked List

Implement reverseDLL

Given the head of a doubly linked list, reverse it in place — the new head should be the old tail — and return the new head. Unlike a singly linked list, where reversal means redirecting a forward-only pointer at every node, a doubly linked list already carries both directions on every node: reversing it is simply swapping each node's own next and prev pointers. Whatever a node used to consider "forward," it now considers "backward," and vice versa — no traversal order needs to be rebuilt, just the meaning of the two pointers each node already had.

Example 1:

Input: head = [6,3,8,1,9]

Output: [9,1,8,3,6]

Example 2:

Input: head = [1]

Output: [1]

Example 3:

Input: head = []

Output: []

+ 4 hidden test cases run on Submit.

Constraints:

  • 0 ≤ number of nodes in head ≤ 200
  • -1000 ≤ node value ≤ 1000
  • This platform's judge reads back only the forward (next) traversal — a real doubly linked implementation reverses by swapping each node's own .next and .prev, not by copying values

head =

[6, 3, 8, 1, 9]