One child is no leaf
transcript
A tree has leaves at different depths. You want the depth of the nearest one. One small mistake ruins the answer. It is about a missing child.
The root has only a left child. The left child is a leaf. A missing child counted as zero gives a minimum of zero. The answer is one. That is wrong. The root is not a leaf. The leaf is at depth two.
If both children are missing, the node is a leaf. If one child is missing, use the other child. Only if both exist, take the smaller depth.
The wrong version returns one for this tree. The fixed version returns two.
Test a tree of one node, where the root is the leaf. Test a chain where every node has exactly one child. Test a root that has only one child, as in the lesson.
A leaf has no children. Never count a missing child as real. Full breakdown in the lecture.