文章 2015-08-15 来自:开发者社区

[LeetCode] Minimum Depth of Binary Tree

This problem is just similar to Minimum Depth of Binary Tree. The first solution also uses recursion (not sure whether it can be called DFS). 1 class Solution { 2 public: 3 int minDepth(TreeNode....

文章 2014-12-30 来自:开发者社区

[LeetCode]111.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. 【分析】 类似于:LeetCode之Maximum Depth...

文章 2014-11-29 来自:开发者社区

LeetCode:111_Minimum Depth of Binary Tree | 二叉树的最小深度 | Easy

要求:此题正好和Maximum Depth of Binary Tree一题是相反的,即寻找二叉树的最小的深度值:从根节点到最近的叶子节点的距离。 结题思路:和找最大距离不同之处在于:找最小距离要注意(l<r)? l+1:r+1的区别应用,因为可能存在左右子树为空的情况,此时值就为0,但显然值是不为0的(只有当二叉树为空才为0),所以,在这里注意一下即可! 代码如下: 1 struct...

本页面内关键词为智能算法引擎基于机器学习所生成,如有任何问题,可在页面下方点击"联系我们"与我们沟通。

算法编程

开发者社区在线编程频道官方技术圈。包含算法资源更新,周赛动态,每日一题互动。

+关注