Recursive DFS JavaScript Solution


  • 0
    P
    var maxDepth = function(root) {
        return dfs(root);
        
        function dfs(node) {
            if(!node) return 0;
            
            let leftDepth = 1 + dfs(node.left);
            let rightDepth = 1 + dfs(node.right);
            return leftDepth > rightDepth ? leftDepth : rightDepth;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.