Click here to see the full article post
Maybe BFS is better for this problem. Instead of traversing all nodes, BFS return immediately when traverse the d-th level.
The above flash illustrations are short of the node 6 's left child, aren't they? or am I just misunderstanding the question? It says "create two tree nodes with value v as N's left subtree root and right subtree root." but the node with value 6 only got right child with value v.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.