From 4f96f64e3d6f54eac978bdea355c22060f80d1ee Mon Sep 17 00:00:00 2001
From: jojoo15 <75017412+jojoo15@users.noreply.github.com>
Date: Tue, 18 May 2021 15:59:48 +0200
Subject: [PATCH 1/5] =?UTF-8?q?Update=200530.=E4=BA=8C=E5=8F=89=E6=90=9C?=
=?UTF-8?q?=E7=B4=A2=E6=A0=91=E7=9A=84=E6=9C=80=E5=B0=8F=E7=BB=9D=E5=AF=B9?=
=?UTF-8?q?=E5=B7=AE.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
added python version of code
---
.../0530.二叉搜索树的最小绝对差.md | 27 ++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)
diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md
index 903ebf78..347d66d1 100644
--- a/problems/0530.二叉搜索树的最小绝对差.md
+++ b/problems/0530.二叉搜索树的最小绝对差.md
@@ -177,8 +177,29 @@ class Solution {
```
Python:
-
-
+```python
+# Definition for a binary tree node.
+# class TreeNode:
+# def __init__(self, val=0, left=None, right=None):
+# self.val = val
+# self.left = left
+# self.right = right
+class Solution:
+ def getMinimumDifference(self, root: TreeNode) -> int:
+ res = []
+ r = float("inf")
+ def buildaList(root): //把二叉搜索树转换成有序数组
+ if not root: return None
+ if root.left: buildaList(root.left) //左
+ res.append(root.val) //中
+ if root.right: buildaList(root.right) //右
+ return res
+
+ buildaList(root)
+ for i in range(len(res)-1): // 统计有序数组的最小差值
+ r = min(abs(res[i]-res[i+1]),r)
+ return r
+```
Go:
@@ -188,4 +209,4 @@ Go:
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
-
\ No newline at end of file
+
From 41272638670e6da93171dfce8af63d5da42d4e36 Mon Sep 17 00:00:00 2001
From: "qingyi.liu"
Date: Tue, 18 May 2021 22:51:51 +0800
Subject: [PATCH 2/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0111.=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E6=9C=80=E5=B0=8F=E6=B7=B1=E5=BA=A6=20JavaSc?=
=?UTF-8?q?ript=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
problems/0111.二叉树的最小深度.md | 47 +++++++++++++++++++++++
1 file changed, 47 insertions(+)
diff --git a/problems/0111.二叉树的最小深度.md b/problems/0111.二叉树的最小深度.md
index 01b6c89c..5605e13d 100644
--- a/problems/0111.二叉树的最小深度.md
+++ b/problems/0111.二叉树的最小深度.md
@@ -302,6 +302,53 @@ class Solution:
Go:
+JavaScript:
+
+递归法:
+
+```javascript
+/**
+ * @param {TreeNode} root
+ * @return {number}
+ */
+var minDepth1 = function(root) {
+ if(!root) return 0;
+ // 到叶子节点 返回 1
+ if(!root.left && !root.right) return 1;
+ // 只有右节点时 递归右节点
+ if(!root.left) return 1 + minDepth(root.right);、
+ // 只有左节点时 递归左节点
+ if(!root.right) return 1 + minDepth(root.left);
+ return Math.min(minDepth(root.left), minDepth(root.right)) + 1;
+};
+```
+
+迭代法:
+
+```javascript
+/**
+* @param {TreeNode} root
+* @return {number}
+*/
+var minDepth = function(root) {
+ if(!root) return 0;
+ const queue = [root];
+ let dep = 0;
+ while(true) {
+ let size = queue.length;
+ dep++;
+ while(size--){
+ const node = queue.shift();
+ // 到第一个叶子节点 返回 当前深度
+ if(!node.left && !node.right) return dep;
+ node.left && queue.push(node.left);
+ node.right && queue.push(node.right);
+ }
+ }
+};
+```
+
+
-----------------------
From cf6ec4f65a8ee43a15c29f0a380cfac5f809a8dd Mon Sep 17 00:00:00 2001
From: X-shuffle <53906918+X-shuffle@users.noreply.github.com>
Date: Tue, 18 May 2021 22:58:00 +0800
Subject: [PATCH 3/5] =?UTF-8?q?Update=20=E4=BA=8C=E5=8F=89=E6=A0=91?=
=?UTF-8?q?=E7=9A=84=E8=BF=AD=E4=BB=A3=E9=81=8D=E5=8E=86.md?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加 二叉树的迭代遍历 GO版本
---
problems/二叉树的迭代遍历.md | 102 +++++++++++++++++++++++++++
1 file changed, 102 insertions(+)
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index 2647616b..d228077b 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -163,7 +163,109 @@ Python:
Go:
+> 迭代法前序遍历
+```go
+//迭代法前序遍历
+/**
+ type Element struct {
+ // 元素保管的值
+ Value interface{}
+ // 内含隐藏或非导出字段
+}
+
+func (l *List) Back() *Element
+前序遍历:中左右
+压栈顺序:右左中
+ **/
+func preorderTraversal(root *TreeNode) []int {
+ if root == nil {
+ return nil
+ }
+ var stack = list.New()
+ stack.PushBack(root.Right)
+ stack.PushBack(root.Left)
+ res:=[]int{}
+ res=append(res,root.Val)
+ for stack.Len()>0 {
+ e:=stack.Back()
+ stack.Remove(e)
+ node := e.Value.(*TreeNode)//e是Element类型,其值为e.Value.由于Value为接口,所以要断言
+ if node==nil{
+ continue
+ }
+ res=append(res,node.Val)
+ stack.PushBack(node.Right)
+ stack.PushBack(node.Left)
+ }
+ return res
+}
+```
+
+> 迭代法后序遍历
+
+```go
+//后续遍历:左右中
+//压栈顺序:中右左(按照前序遍历思路),再反转结果数组
+func postorderTraversal(root *TreeNode) []int {
+ if root == nil {
+ return nil
+ }
+ var stack = list.New()
+ stack.PushBack(root.Left)
+ stack.PushBack(root.Right)
+ res:=[]int{}
+ res=append(res,root.Val)
+ for stack.Len()>0 {
+ e:=stack.Back()
+ stack.Remove(e)
+ node := e.Value.(*TreeNode)//e是Element类型,其值为e.Value.由于Value为接口,所以要断言
+ if node==nil{
+ continue
+ }
+ res=append(res,node.Val)
+ stack.PushBack(node.Left)
+ stack.PushBack(node.Right)
+ }
+ for i:=0;i 迭代法中序遍历
+
+```go
+//迭代法中序遍历
+func inorderTraversal(root *TreeNode) []int {
+ rootRes:=[]int{}
+ if root==nil{
+ return nil
+ }
+ stack:=list.New()
+ node:=root
+ //先将所有左节点找到,加入栈中
+ for node!=nil{
+ stack.PushBack(node)
+ node=node.Left
+ }
+ //其次对栈中的每个节点先弹出加入到结果集中,再找到该节点的右节点的所有左节点加入栈中
+ for stack.Len()>0{
+ e:=stack.Back()
+ node:=e.Value.(*TreeNode)
+ stack.Remove(e)
+ //找到该节点的右节点,再搜索他的所有左节点加入栈中
+ rootRes=append(rootRes,node.Val)
+ node=node.Right
+ for node!=nil{
+ stack.PushBack(node)
+ node=node.Left
+ }
+ }
+ return rootRes
+}
+```
From 44c8ce6a4f54869008961c62d2728548b6f24e04 Mon Sep 17 00:00:00 2001
From: X-shuffle <53906918+X-shuffle@users.noreply.github.com>
Date: Wed, 19 May 2021 10:03:09 +0800
Subject: [PATCH 4/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E8=BF=AD=E4=BB=A3=E9=81=8D=E5=8E=86=20GO?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加 二叉树的迭代遍历 GO版本
---
problems/二叉树的迭代遍历.md | 1 -
1 file changed, 1 deletion(-)
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index d228077b..10e7e7b4 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -268,7 +268,6 @@ func inorderTraversal(root *TreeNode) []int {
```
-
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
From a57b6385c4ceccb7900cb9dc41a7eb3d6a59d2e5 Mon Sep 17 00:00:00 2001
From: X-shuffle <53906918+X-shuffle@users.noreply.github.com>
Date: Wed, 19 May 2021 10:07:22 +0800
Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E4=BA=8C=E5=8F=89?=
=?UTF-8?q?=E6=A0=91=E7=9A=84=E8=BF=AD=E4=BB=A3=E9=81=8D=E5=8E=86=20GO?=
=?UTF-8?q?=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
添加 二叉树的迭代遍历 GO版本
---
problems/二叉树的迭代遍历.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/problems/二叉树的迭代遍历.md b/problems/二叉树的迭代遍历.md
index 10e7e7b4..a1906469 100644
--- a/problems/二叉树的迭代遍历.md
+++ b/problems/二叉树的迭代遍历.md
@@ -205,6 +205,7 @@ func preorderTraversal(root *TreeNode) []int {
> 迭代法后序遍历
```go
+//迭代法后序遍历
//后续遍历:左右中
//压栈顺序:中右左(按照前序遍历思路),再反转结果数组
func postorderTraversal(root *TreeNode) []int {