Skip to content

Practice Flatten Binary Tree to Linked List

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#114
LeetCode Problem

Flatten Binary Tree to Linked List

Problem Statement

Convert the given binary tree to a chain using TreeNode nodes in preorder: visit a node, then its left subtree, then its right subtree. Every left pointer must become null, and each right pointer must refer to the next node in this order. The final node has no next node.

Source: Flatten Binary Tree to Linked List on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
root = [1,2,5,3,4,null,6]
Output
[1,null,2,null,3,null,4,null,5,null,6]

# Example 2

Input
root = []
Output
[]

# Example 3

Input
root = [0]
Output
[0]

Constraints

The number of nodes in the tree is in the range [0, 2000].
-100 <= Node.val <= 100

Related LeetCode Problems

Practice more problems similar to Flatten Binary Tree to Linked List.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.