题目描述
我的解法
思路
使用和求最大深度时类似的递归法,只不过将单层逻辑中的获取左右子树最大值变成过去左右子树最小值。但是出错了
错误时的情况
下图来源于公众号代码随想录
出错的Java代码
class Solution {
public int minDepth(TreeNode root) {
return getMinDepth(root);
}
public int getMinDepth(TreeNode node){
if(node == null){
return 0;}
int minLeftDepth = getMinDepth(node.left);
int minRightDepth = getMinDepth