/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
Stack<TreeNode> S = new Stack<TreeNode>(); List<List<TreeNode>> list = new List<List<TreeNode>>(); private void postNode(TreeNode node)
{
if (node != null)
{
S.Push(node);
if (node.left != null)
{
postNode(node.left);
}
if (node.right != null)
{
postNode(node.right);
} if (node.left == null && node.right == null)
{
list.Add(S.ToList());
}
S.Pop();
}
} public int MinDepth(TreeNode root)
{
postNode(root); var min = int.MaxValue; if (list.Count == )
{
min = ;
} foreach (var l in list)
{
var count = l.Count;
if (count < min)
{
min = count;
}
} return min;
}
}

https://leetcode.com/problems/minimum-depth-of-binary-tree/#/description

补充一个python的实现:

 class Solution:
def minDepth(self, root: TreeNode) -> int:
if root == None:
return
left = self.minDepth(root.left)
right = self.minDepth(root.right)
if left == or right == :
return left + right +
return min(left,right) +

最新文章

  1. 解决Trauncate table没权限
  2. IE6-IE11兼容性问题列表及解决办法总结
  3. 看StackOverflow如何用25台服务器撑起5.6亿的月PV
  4. 微信内置浏览器中,点击下拉框出现页面乱跳转现象(iphone)
  5. SSH框架应用中常用Jar包用途介绍
  6. c c++ 函数入口和出口的hook(gcc 编译选项),然后打印出函数调用关系的方法
  7. 详解 Android 的 Activity 组件
  8. Java学习----this和super(在继承中)
  9. BlazeDS简介(转自openkk的日志)
  10. jQuery特效 隔行变色
  11. [原创].NET 业务框架开发实战之九 Mapping属性原理和验证规则的实现策略
  12. 通过游戏认识 --- JQuery与原生JS的差异
  13. Caused by: java.lang.ClassNotFoundException: org.hibernate.service.jta.platform.spi.JtaPlatform
  14. 新概念英语(1-3)Sorry, sir
  15. PowerShell 官方下载地址
  16. 从零开始写自己的PHP框架系列教程(一)[core.php]
  17. spring静态注入
  18. XBOX360更新游戏封皮(FSD自制系统)
  19. 3.HBase In Action 第一章-HBase简介(1.1.1 大数据你好呀)
  20. jQuery统计上传文件的大小

热门文章

  1. UVA-11903 Just Finish it up
  2. EPANET头文件解读系列6——HASH.H
  3. Django中CSS加载background url(&#39;&#39;)问题
  4. sgu 137. Funny Strings 线性同余,数论,构造 难度:3
  5. Java——基本语法
  6. BootStrap使用
  7. New Concept English Two 25 67
  8. 三十分钟理解:双调排序Bitonic Sort,适合并行计算的排序算法
  9. CF 432D
  10. gradle 代理设置