Doubly Linked List to Array

Given a non-null node from a doubly linked list (which might not be the head), return an array of values from head to tail.

1def to_array(node: 'DoublyNode') -> list[int]:
2 cur = node
3 while cur.prev:
4 cur = cur.prev
5 res = []
6 while cur:
7 res.append(cur.val)
8 cur = cur.next
9 return res
1
0
2
1
cur
3
2
4
3
action=move prev
Step 1 / 3
Step 1:
Walk backwards to find the head.
Pointers: cur=2
Focus: select @ [2]
action="move prev"