"""# 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,node:"Optional[Node]")->List[int]:whilenode.prev:node=node.prevans=[]whilenode:ans.append(node.val)node=node.nextreturnans
1 2 3 4 5 6 7 8 9101112131415161718192021
/*// Definition for a Node.class Node { public int val; public Node prev; public Node next;};*/classSolution{publicint[]toArray(Nodenode){while(node!=null&&node.prev!=null){node=node.prev;}varans=newArrayList<Integer>();for(;node!=null;node=node.next){ans.add(node.val);}returnans.stream().mapToInt(i->i).toArray();}}
/** * Definition for a Node. * type Node struct { * Val int * Next *Node * Prev *Node * } */functoArray(node*Node)(ans[]int){fornode!=nil&&node.Prev!=nil{node=node.Prev}for;node!=nil;node=node.Next{ans=append(ans,node.Val)}return}