We’re preparing your current view and syncing the latest data.
You are given a 2D integer array descriptions where each descriptions[i] = [parent_i, child_i, isLeft_i] indicates that parent_i is the parent of child_i in a binary tree. isLeft_i is 1 if child_i is the left child of parent_i, and 0 if child_i is the right child of parent_i. Construct the binary tree described by the descriptions and return its root.
An integer 2D array descriptions where each element is [parent, child, isLeft].
Return the root node of the constructed binary tree.
1 <= descriptions.length <= 10^4; descriptions[i].length == 3; 1 <= parent_i, child_i <= 10^5; isLeft_i is either 0 or 1; The provided descriptions form a valid binary tree.
Example 1
Input
[[20,15,1],[20,17,0],[15,10,1]]
Output
Root node representing the binary tree:
20
/
15 17
/
10Explanation
20 is the root, 15 is left child of 20, 17 is right child of 20, and 10 is left child of 15.