1 Star 0 Fork 0

yy/LeetCode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
104-二叉树的最大深度.js 655 Bytes
一键复制 编辑 原始数据 按行查看 历史
yy 提交于 2022-01-13 20:50 +08:00 . 104-二叉树的最大深度
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @return {number}
*/
var maxDepth = function(root) {
let deep = 0;
let depth = function(root,d){
if(!root) {
return;
}else{
d++;
}
if(!root.left && !root.right){
deep = Math.max(deep,d);
}
depth(root.left,d);
depth(root.right,d);
}
depth(root,deep);
return deep;
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yaoyuana/LeetCode.git
git@gitee.com:yaoyuana/LeetCode.git
yaoyuana
LeetCode
LeetCode
master

搜索帮助