LeetCode 111:二叉树的最小深度(java)
题目:

解答:
/**
* 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) {
int right=0;
int left=0;
if(root==null)
return 0;
if(root.left==null)
return 1+minDepth(root.right);
if(root.right==null)
return 1+minDepth(root.left);
return 1+Math.min(minDepth(root.right),minDepth(root.left));
}
}
本文详细解析了LeetCode111题“二叉树的最小深度”的解题思路及Java实现方法,通过递归算法高效求解二叉树的最小深度。
&spm=1001.2101.3001.5002&articleId=90246712&d=1&t=3&u=848ca87a73c643fb85f0465e3a64d65d)
1219

被折叠的 条评论
为什么被折叠?



