LeetCode-the depth of the binary tree

Title description

Problem-solving ideas

  • Using recursive thinking, go to the maximum of the maximum depth of the left child and the maximum depth of the right child + 1

Problem-solving code

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

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

Guess you like

Origin blog.csdn.net/sinat_41696687/article/details/114921545