Talentd
FleetCode

3263. Convert Doubly Linked List to Array I

Easy95.0% acceptancePremium elsewhere, free here

You are given the head of 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,3,2,1]

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

Example 2:

Input: head = [2,2,2,2,2]

Output: [2,2,2,2,2]

Example 3:

Input: head = [3,2,3,2,3,2]

Output: [3,2,3,2,3,2]

Constraints:

  • The number of nodes in the given list is in the range [1, 50].
  • 1 <= Node.val <= 50
2:00
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,3,2,1]
Input
[2,2,2,2,2]
Input
[3,2,3,2,3,2]
Your code is saved on this device.Solution