LeetCode算法笔记-Day52104. Maximum Depth of Binary Tree Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. example: 12345678Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7return its depth = 3. Analyse:DFS深度优先遍历 My Answer:1234567891011121314151617181920212223242526/** * Definition for a binary tree node. * function TreeNode(val) { * this.val = val; * this.left = this.right = null; * } *//** * @param {TreeNode} root * @return {number} */var maxDepth = function(root) { let res = 0; if(!root) return res; let dfs = (node,_deep)=>{ if(!!node){ if(_deep>res) res = _deep; dfs(node.left,_deep+1); dfs(node.right,_deep+1); } } dfs(root,1); return res;};