
描述
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.
分析
广度优先遍历可解,找到第一个叶子节点停止搜索返回高度。时间O(n),空间O(n)。
解题
Python
1 |
class (object): |

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.
广度优先遍历可解,找到第一个叶子节点停止搜索返回高度。时间O(n),空间O(n)。
1 |
class (object): |
近期评论