LeetCode 二叉树的最小深度
2014-10-20 19:13
357 查看
计算二叉树的最小深度。最小深度定义为从root到叶子节点的最小路径。
Java版本如下:
Java版本如下:
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public int minDepth(TreeNode root) { if(root == null) return 0; if(root.left == null)return minDepth(root.right) + 1; if(root.right == null) return minDepth(root.left) + 1; return Math.min(minDepth(root.left), minDepth(root.right)) + 1; } }
相关文章推荐
- [LeetCode 111] - 二叉树的最小深度 (Minimum Depth of Binary Tree)
- [LeetCode-111] Minimum Depth of Binary Tree (二叉树最小深度)
- LeetCode:寻找二叉树的最小深度
- [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度
- LeetCode 111. Minimum Depth of Binary Tree (二叉树最小的深度)
- leetCode 111.Minimum Depth of Binary Tree(二叉树最小深度) 解题思路和方法
- LeetCode:111_Minimum Depth of Binary Tree | 二叉树的最小深度 | Easy
- leetcode 111-二叉树最小深度
- leetCode 笔记 ————二叉树最小深度
- leetcode之二叉树类之二叉树深度系列-----104/111/110/108/109 二叉树最大/最小深度/AVL树的判断和由有序序列生成(牵扯分治相关,OJ105/106)
- 【LeetCode-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree(二叉树的最小深度)】
- LeetCode 二叉树的最小深度
- LeetCode 111. Minimum Depth of Binary Tree(二叉树最小深度)
- Leetcode 95. Unique Binary Search Trees II及二叉树最大最小深度镜像树总结
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
- LeetCode—二叉树的最大最小深度
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- leetcode 二叉树的最小深度
- [LeetCode]111. Minimum Depth of Binary Tree--二叉树的最小深度
- [Leetcode] The minimum depth of binary tree二叉树的最小深度