flâneur

Validate Binary Tree Nodes - LeetCode

leetcode.com · saved by 1 readers

You have n binary tree nodes numbered from 0 to n - 1 where node i has two children leftChild[i] and rightChild[i], return true if and only if all the given nodes form exactly one valid binary tree. If node i has no left child then leftChild[i] will equal -1, similarly for the right child. Note that the nodes have no values and that we only use the node numbers in this problem. Example 1: Example 2: Example 3: Constraints: 1. Please don't post any solutions in this discussion. 2. The problem discussion is for asking questions about the problem or for sharing tips - anything except for solutions. 3. If you'd like to share your solution for feedback and ideas, please head to the solutions tab and post it there. When asked to validate the binary tree nodes we are really being asked to ensure: 1. We have exactly 1 node(root) with no parent node. 2. Each node aside from root has at most 1 parent node. 3. All nodes are connected to root by association. This question is not very difficult but

saved by