Minimum Depth of Binary Tree----easy
来源:互联网 发布:js动态为div添加style 编辑:程序博客网 时间:2024/06/06 10:53
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.
Tags:Tree Depth-first Search
- 对仅有左/右子树的情况取该子树递归计算深度
- 对有左右子树或无子树情况直接递归计算深度
public class Solution { public int minDepth(TreeNode root) { if(root==null)return 0; else if(root.left == null && root.right != null) return 1+minDepth(root.right); else if(root.left != null && root.right == null) return 1+minDepth(root.left); else{ int i = minDepth(root.left); int j = minDepth(root.right); return 1+(i>=j?j:i); } }}
0 0
- Minimum Depth of Binary Tree----easy
- Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree(Tree-Easy)
- [Leetcode 104, Easy] Minimum (Maximum) Depth of Binary Tree
- Minimum Depth of Binary Tree——LeetCode(Easy)
- [Leetcode 111, Easy] Minimum Depth of Binary Tree
- <LeetCode><Easy> 111 Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree [easy] (Python)
- Easy-题目37:111. Minimum Depth of Binary Tree
- Leetcode 111. Minimum Depth of Binary Tree (Easy) (cpp)
- LeetCode解题报告 111. Minimum Depth of Binary Tree [easy]
- 【Leetcode-easy-111】Minimum Depth of Binary Tree
- LeetCode-Easy刷题(25) Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- php实现文件下载和多文件上传
- 数据挖掘之大数据流处理
- 通过getPropertyValue 取得最终的CSS样式
- python packages管理工具---pip
- I Hate It(更新点,查找最大值)
- Minimum Depth of Binary Tree----easy
- 没有办法掌控命数,就掌控内心
- Java+oracle树查询实现easyui中tree使用的json
- union和enum的使用
- 关于在cocos2dx中继承Sprite的分析与技巧
- Symmetric Tree----easy
- Head First Python(推导数据)
- mac 启动nexus
- Atitit.ide代码块折叠插件 eclipse