Ad7571af6c8c66794d1f32e66a7364a1
(难度Easy) Problem 111. Minimum Depth of Binary Tree(二叉树最浅深度)

Minimum Depth of Binary Tree

Difficulty

Easy

Description

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.

题意

给定一棵二叉树,求二叉树中最浅的深度。树上的深度指的是叶子到树根的距离。

题解

之前我们做过很多和二叉树深度有关的问题,一般来说树上的问题离不开递归。比如之前我们求解树上的深度的时候,都是通过递归解决的。在递归的参数当中传入深度,通过每次递归的时候调整,来获取叶子节点的深度。

top Created with Sketch.