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:
Given binary tree [3,9,20,null,null,15,7]
,
3 / \ 9 20 / \ 15 7
return its minimum depth = 2.
# -*- coding:utf-8 -*-
__author__ = 'yangxin_ryan'
"""
Solutions:
求二叉树的最小深度
我们可以先列举所有情况:
1.当节点为叶子结点,深度为1
2.当根节点为None,深度为0
3.当节点只有左孩子(或右孩子)时,深度为左孩子(右孩子)+ 1
4.当节点既有左孩子又有右孩子时,深度为min(左孩子,右孩子) + 1
5.递归上面的情况
""&#