/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
class Solution {
public int minDepth(TreeNode root) {
if(root == null){
return 0;
}
if((root.left == null) && (root.right == null)){
return 1;
}
int min_depth = Integer.MAX_VALUE;
if(root.left != null){
min_depth = Math.min(minDepth(root.left),min_depth);
}
if(root.right != null){
min_depth = Math.min(minDepth(root.right),min_depth);
}
return min_depth+1;
}
}
相关文章
- LeetCode算法题-Second Minimum Node In a Binary Tree(Java实现)
- 【leetcode】Minimum Depth of Binary Tree
- LeetCode算法题-Minimum Depth of Binary Tree(Java实现)
- [LeetCode] Minimum Depth of Binary Tree 二叉树最小深度
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
- [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度
- 【LeetCode OJ】Minimum Depth of Binary Tree
- LeetCode:Minimum Depth of Binary Tree,Maximum Depth of Binary Tree
- LeetCode算法题-Diameter of Binary Tree(Java实现)
- leetcode 111 minimum depth of binary tree