Talentd
FleetCode

3294. Convert Doubly Linked List to Array II

Medium83.3% acceptancePremium elsewhere, free here

You are given an arbitrary node from a doubly linked list, which contains nodes that have a next pointer and a previous pointer.

Return an integer array which contains the elements of the linked list in order.

Example 1:

Input: head = [1,2,3,4,5], node = 5

Output: [1,2,3,4,5]

Example 2:

Input: head = [4,5,6,7,8], node = 8

Output: [4,5,6,7,8]

Constraints:

  • The number of nodes in the given list is in the range [1, 500].
  • 1 <= Node.val <= 1000
  • All nodes have unique Node.val.

Hints open one at a time

Hint 1
Use the pointer to the previous node to reach the head node.
5:28
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
[1,2,3,4,5]
5
Input
[4,5,6,7,8]
8
Your code is saved on this device.Solution