From dc3517c1b089933ed21f69b807bcc00aba887baa Mon Sep 17 00:00:00 2001 From: Yuhao Ju Date: Wed, 30 Nov 2022 15:36:25 +0800 Subject: [PATCH] =?UTF-8?q?update=200104.=E4=BA=8C=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6:=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=80=E6=AE=B5=20js=20=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0104.二叉树的最大深度.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index ee7bd50e..03322c9a 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -59,7 +59,7 @@ int getdepth(treenode* node) if (node == NULL) return 0; ``` -3. 确定单层递归的逻辑:先求它的左子树的深度,再求的右子树的深度,最后取左右深度最大的数值 再+1 (加1是因为算上当前中间节点)就是目前节点为根节点的树的深度。 +3. 确定单层递归的逻辑:先求它的左子树的深度,再求右子树的深度,最后取左右深度最大的数值 再+1 (加1是因为算上当前中间节点)就是目前节点为根节点的树的深度。 代码如下: @@ -591,15 +591,15 @@ var maxdepth = function(root) { var maxdepth = function(root) { //使用递归的方法 递归三部曲 //1. 确定递归函数的参数和返回值 - const getdepth=function(node){ + const getdepth = function(node) { //2. 确定终止条件 - if(node===null){ + if(node === null) { return 0; } //3. 确定单层逻辑 - let leftdepth=getdepth(node.left); - let rightdepth=getdepth(node.right); - let depth=1+Math.max(leftdepth,rightdepth); + let leftdepth = getdepth(node.left); + let rightdepth = getdepth(node.right); + let depth = 1 + Math.max(leftdepth, rightdepth); return depth; } return getdepth(root);