From e36dc6a5841d6aa3d719635538ee84df235c9a34 Mon Sep 17 00:00:00 2001 From: Galaxies2580 Date: Mon, 15 Aug 2022 10:22:46 +0800 Subject: [PATCH 1/3] Go --- ....完全二叉树的节点个数Go版本.md | 25 +++++++++++++++++++ 添加559.n叉树的最大深度Go版本.md | 22 ++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 添加0222.完全二叉树的节点个数Go版本.md create mode 100644 添加559.n叉树的最大深度Go版本.md diff --git a/添加0222.完全二叉树的节点个数Go版本.md b/添加0222.完全二叉树的节点个数Go版本.md new file mode 100644 index 00000000..752ace88 --- /dev/null +++ b/添加0222.完全二叉树的节点个数Go版本.md @@ -0,0 +1,25 @@ +```go +func countNodes(root *TreeNode) int { + if root == nil { + return 0 + } + q := list.New() + q.PushBack(root) + res := 0 + for q.Len() > 0 { + n := q.Len() + for i := 0; i < n; i++ { + node := q.Remove(q.Front()).(*TreeNode) + if node.Left != nil { + q.PushBack(node.Left) + } + if node.Right != nil { + q.PushBack(node.Right) + } + res++ + } + } + return res +} +``` + diff --git a/添加559.n叉树的最大深度Go版本.md b/添加559.n叉树的最大深度Go版本.md new file mode 100644 index 00000000..77ca332c --- /dev/null +++ b/添加559.n叉树的最大深度Go版本.md @@ -0,0 +1,22 @@ +```go +func maxDepth(root *Node) int { + if root == nil { + return 0 + } + q := list.New() + q.PushBack(root) + depth := 0 + for q.Len() > 0 { + n := q.Len() + for i := 0; i < n; i++ { + node := q.Remove(q.Front()).(*Node) + for j := range node.Children { + q.PushBack(node.Children[j]) + } + } + depth++ + } + return depth +} +``` + From f59621fdc5b0917f048767f64d449b6f4e7ea40b Mon Sep 17 00:00:00 2001 From: Galaxies2580 <82326525+Galaxies2580@users.noreply.github.com> Date: Mon, 15 Aug 2022 10:24:40 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A00222.=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E7=9A=84=E8=8A=82=E7=82=B9=E4=B8=AA?= =?UTF-8?q?=E6=95=B0Go=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加0222.完全二叉树的节点个数Go版本 --- 添加0222.完全二叉树的节点个数Go版本.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/添加0222.完全二叉树的节点个数Go版本.md b/添加0222.完全二叉树的节点个数Go版本.md index 752ace88..6001e7b7 100644 --- a/添加0222.完全二叉树的节点个数Go版本.md +++ b/添加0222.完全二叉树的节点个数Go版本.md @@ -19,7 +19,7 @@ func countNodes(root *TreeNode) int { res++ } } - return res + return res } ``` From c50085df84471905957bb5990fba5ed4825c5f9b Mon Sep 17 00:00:00 2001 From: Galaxies2580 <82326525+Galaxies2580@users.noreply.github.com> Date: Mon, 15 Aug 2022 10:25:03 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=B7=BB=E5=8A=A0559.n=E5=8F=89=E6=A0=91?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=B7=B1=E5=BA=A6Go=E7=89=88?= =?UTF-8?q?=E6=9C=AC.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加559.n叉树的最大深度Go版本.md --- 添加559.n叉树的最大深度Go版本.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/添加559.n叉树的最大深度Go版本.md b/添加559.n叉树的最大深度Go版本.md index 77ca332c..3172837d 100644 --- a/添加559.n叉树的最大深度Go版本.md +++ b/添加559.n叉树的最大深度Go版本.md @@ -16,7 +16,7 @@ func maxDepth(root *Node) int { } depth++ } - return depth + return depth } ```