Minimum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children.
(二叉树的最低深度)
Example:
1. 递归
注意左(右)子树深度为0的地方,也就是当左(右)子树为空时,应该按照右(左)子树的深度计算。具体实现过程如下:
1 | # Definition for a binary tree node. |