From ca4c4f7f8be13af4ec8106fdc6e07ca26d6927c1 Mon Sep 17 00:00:00 2001 From: ZGQ Date: Wed, 28 Sep 2022 20:07:51 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Update=200129.=E6=B1=82=E6=A0=B9=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=88=B0=E5=8F=B6=E8=8A=82=E7=82=B9=E6=95=B0=E5=AD=97?= =?UTF-8?q?=E4=B9=8B=E5=92=8C.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0129.求根到叶子节点数字之和.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/problems/0129.求根到叶子节点数字之和.md b/problems/0129.求根到叶子节点数字之和.md index 859df39e..bd5107a2 100644 --- a/problems/0129.求根到叶子节点数字之和.md +++ b/problems/0129.求根到叶子节点数字之和.md @@ -320,8 +320,11 @@ TypeScript: ```typescript function sumNumbers(root: TreeNode | null): number { if (root === null) return 0; + // 记录最终结果 let resTotal: number = 0; + // 记录路径中遇到的节点值 const route: number[] = []; + // 递归初始值 route.push(root.val); recur(root, route); return resTotal; @@ -342,6 +345,7 @@ function sumNumbers(root: TreeNode | null): number { }; } function listToSum(nums: number[]): number { + // 数组求和 return Number(nums.join('')); } }; From de017e95441ece804182aec87cfba7f4414cc4a7 Mon Sep 17 00:00:00 2001 From: zihao Tan <53686585+Tcotyledons@users.noreply.github.com> Date: Thu, 29 Sep 2022 09:41:25 +0800 Subject: [PATCH 2/2] =?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.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 104二叉树最大深度贡献java版本的从深度角度的递归法 --- problems/0104.二叉树的最大深度.md | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/problems/0104.二叉树的最大深度.md b/problems/0104.二叉树的最大深度.md index 2bcc9c5c..bcf3a4a3 100644 --- a/problems/0104.二叉树的最大深度.md +++ b/problems/0104.二叉树的最大深度.md @@ -313,6 +313,31 @@ class solution { } ``` +```java +class Solution { + /** + * 递归法(求深度法) + */ + //定义最大深度 + int maxnum = 0; + + public int maxDepth(TreeNode root) { + ans(root,0); + return maxnum; + } + + //递归求解最大深度 + void ans(TreeNode tr,int tmp){ + if(tr==null) return; + tmp++; + maxnum = maxnum