File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -177,8 +177,29 @@ class Solution {
177
177
```
178
178
179
179
Python:
180
-
181
-
180
+ ``` python
181
+ # Definition for a binary tree node.
182
+ # class TreeNode:
183
+ # def __init__(self, val=0, left=None, right=None):
184
+ # self.val = val
185
+ # self.left = left
186
+ # self.right = right
187
+ class Solution :
188
+ def getMinimumDifference (self , root : TreeNode) -> int :
189
+ res = []
190
+ r = float (" inf" )
191
+ def buildaList (root ): // 把二叉搜索树转换成有序数组
192
+ if not root: return None
193
+ if root.left: buildaList(root.left) // 左
194
+ res.append(root.val) // 中
195
+ if root.right: buildaList(root.right) // 右
196
+ return res
197
+
198
+ buildaList(root)
199
+ for i in range (len (res)- 1 ): // 统计有序数组的最小差值
200
+ r = min (abs (res[i]- res[i+ 1 ]),r)
201
+ return r
202
+ ```
182
203
Go:
183
204
184
205
188
209
* 作者微信:[ 程序员Carl] ( https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw )
189
210
* B站视频:[ 代码随想录] ( https://space.bilibili.com/525438321 )
190
211
* 知识星球:[ 代码随想录] ( https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ )
191
- <div align="center"><img src=../pics/公众号.png width=450 alt=> </img ></div >
212
+ <div align="center"><img src=../pics/公众号.png width=450 alt=> </img ></div >
You can’t perform that action at this time.
0 commit comments