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.

解题思路:注意minimum depth最后遍历的那个点,left right都必须为null,JAVA实现如下:

    public int minDepth(TreeNode root) {
if(root==null)
return 0;
else if(root.left==null)
return minDepth(root.right)+1;
else if(root.right==null)
return minDepth(root.left)+1;
else return Math.min(minDepth(root.left),minDepth(root.right))+1;
}

最新文章

  1. 利用WCF创建简单的RESTFul Service
  2. 用Chrome插件对自动化测试TestWriter进行录制
  3. 【CCL】连通区域提取
  4. IOS- 单例
  5. Git使用ssh key
  6. AES加密算法-128位高安全,高速度
  7. 使用cwRsync实现windows下文件定时同步【转】
  8. SharePoint ListTemplateType enumeration
  9. 【最短路】BAPC2014 B Button Bashing (Codeforces GYM 100526)
  10. Python 变量有效范围
  11. Almost Prime
  12. docker异常问题解决
  13. java 字节码 指令集 汇编(转)
  14. [Android Security] APK自我保护 - DEX/APK校验
  15. C++中前置声明的应用与陷阱
  16. 【React】使用 create-react-app 快速构建 React 开发环境
  17. [CF1105D]Kilani and the Game
  18. Kerberos的白银票据详解
  19. java 中的try catch在文件相关操作的使用
  20. ActiveMQ简述

热门文章

  1. ios文件管理
  2. Struts2学习记录-Value Stack(值栈)和OGNL表达式
  3. mysql if()一个奇怪的问题
  4. 【秀优越(xie e)】原来出题也能够这么恶心。
  5. Linux 的计划任务(运维基础|可用于提权)
  6. vs 已经加入了引用,编译还是提示没有加入引用
  7. 【Excle数据透视表】如何快速选取所有标签并标注黄色底纹
  8. SQLAlchemy使用笔记--SQLAlchemy ORM(三)
  9. rtems 4.11 console驱动 (arm, beagle)
  10. java 表示当前时间的第二天的几点