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