问题遇到的现象和发生背景
在https://realduang.github.io/leetcode-in-javascript/list/tree/104.maximumDepthOfBinaryTree.html#dfs%E6%B7%B1%E5%BA%A6%E4%BC%98%E5%85%88%E6%90%9C%E7%B4%A2里看到递归实现求解树的深度。
但是无法理解。求点拨。
问题相关代码,请勿粘贴截图
var maxDepth = function(root) {
if (!root) return 0;
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1;
};
我的想法是:当前在的点的深度就是上一层的深度+1.
但是还是不理解这个代码。。脑袋混乱。