"""# Definition for a Node.class Node: def __init__(self, val, prev=None, next=None): self.val = val self.prev = prev self.next = next"""classSolution:deftoArray(self,root:"Optional[Node]")->List[int]:ans=[]whileroot:ans.append(root.val)root=root.nextreturnans
1 2 3 4 5 6 7 8 9101112131415161718
/*// Definition for a Node.class Node { public int val; public Node prev; public Node next;};*/classSolution{publicint[]toArray(Nodehead){List<Integer>ans=newArrayList<>();for(;head!=null;head=head.next){ans.add(head.val);}returnans.stream().mapToInt(i->i).toArray();}}
/** * Definition for a Node. * type Node struct { * Val int * Next *Node * Prev *Node * } */functoArray(head*Node)(ans[]int){for;head!=nil;head=head.Next{ans=append(ans,head.Val)}return}