LeetCode——二叉树的深度

题目描述

解题思路

  • 使用递归的思想,去左子孩子的最大深度和右子孩子的最大深度中的最大值 + 1

解题代码

var maxDepth = function(root) {
    
    
    if (!root) {
    
    
        return 0;        
    }

    return Math.max(maxDepth(root.left),maxDepth(root.right)) + 1;
};

猜你喜欢

转载自blog.csdn.net/sinat_41696687/article/details/114921545