You are given the head of a doubly linked list, where each node contains an integer value and has both next and prev pointers. Your task is to traverse this doubly linked list and convert it into a regular integer array.
A doubly linked list is a data structure where each node points to both the next node and the previous node in the sequence. This allows for efficient bidirectional traversal, but for this problem, you'll only need to traverse in one direction.
Goal: Return an integer array containing all the values from the doubly linked list in the same order they appear when traversing from head to tail.
Example:
If your doubly linked list looks like: 1 ⇄ 2 ⇄ 3 ⇄ null
Then your output array should be: [1, 2, 3]
Input & Output
Constraints
- The number of nodes in the list is in the range [0, 1000]
- Node values are in the range [-1000, 1000]
- Follow up: Can you solve it using only one pass through the linked list?