Tap here to switch tabs
Problem
Submissions

Problem: Create Binary Tree From Descriptions

Create Binary Tree From Descriptions gives parent-child triples that specify each child's left or right position. Build the described binary tree and return its root.

Statement

You are given a 22D integer array descriptions, where descriptions[i] = [parent_i, child_i, isLeft_i] indicates that parent_i is the parent of child_i in a binary tree.

The value of isLeft_i determines the position of child_i:

  • If isLeft_i =1= 1, then child_i is the left child of parent_i.

  • If isLeft_i =0= 0, then child_i is the right child of parent_i.

Construct the binary tree described by descriptions and return its root node.

Constraints:

  • 1≤1 \leq descriptions.length ≤104\leq 10^4

  • descriptions[i].length =3= 3

  • 1≤1 \leq parent_i, child_i ≤105\leq 10^5

  • 0≤0 \leq isLeft_i ≤1\leq 1

  • The binary tree described by descriptions is valid.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Create Binary Tree From Descriptions

Create Binary Tree From Descriptions gives parent-child triples that specify each child's left or right position. Build the described binary tree and return its root.

Statement

You are given a 22D integer array descriptions, where descriptions[i] = [parent_i, child_i, isLeft_i] indicates that parent_i is the parent of child_i in a binary tree.

The value of isLeft_i determines the position of child_i:

  • If isLeft_i =1= 1, then child_i is the left child of parent_i.

  • If isLeft_i =0= 0, then child_i is the right child of parent_i.

Construct the binary tree described by descriptions and return its root node.

Constraints:

  • 1≤1 \leq descriptions.length ≤104\leq 10^4

  • descriptions[i].length =3= 3

  • 1≤1 \leq parent_i, child_i ≤105\leq 10^5

  • 0≤0 \leq isLeft_i ≤1\leq 1

  • The binary tree described by descriptions is valid.