Skip to content

Practice Create Binary Tree From Descriptions

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

Medium#2196
LeetCode Problem

Create Binary Tree From Descriptions

Problem Statement

Each [parent,child,isLeft] in descriptions names node values: isLeft = 1 attaches child as the left child of parent, and 0 attaches it as the right child. Values identify unique nodes. Construct and return the root of the described binary tree; the input guarantees a valid tree.

Source: Create Binary Tree From Descriptions on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]
Output
[50,20,80,15,17,19]

# Example 2

Input
descriptions = [[1,2,1],[2,3,0],[3,4,1]]
Output
[1,2,null,null,3,4]

Constraints

1 <= descriptions.length <= 10^4
descriptions[i].length == 3
1 <= parenti, childi <= 10^5
0 <= isLefti <= 1
The binary tree described by descriptions is valid.

Related LeetCode Problems

Practice more problems similar to Create Binary Tree From Descriptions.

Review your practice with PhantomCodeAI

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