update 0530.二叉搜索树的最小绝对差: 删除 go 冗余代码

This commit is contained in:
Yuhao Ju
2022-12-04 14:27:21 +08:00
committed by GitHub
parent d32e8f54c8
commit a4d7ed6142

View File

@ -248,28 +248,6 @@ class Solution:
## Go ## Go
中序遍历,然后计算最小差值 中序遍历,然后计算最小差值
```go
func getMinimumDifference(root *TreeNode) int {
var res []int
findMIn(root,&res)
min:=1000000//一个比较大的值
for i:=1;i<len(res);i++{
tempValue:=res[i]-res[i-1]
if tempValue<min{
min=tempValue
}
}
return min
}
//中序遍历
func findMIn(root *TreeNode,res *[]int){
if root==nil{return}
findMIn(root.Left,res)
*res=append(*res,root.Val)
findMIn(root.Right,res)
}
```
```go ```go
// 中序遍历的同时计算最小值 // 中序遍历的同时计算最小值
func getMinimumDifference(root *TreeNode) int { func getMinimumDifference(root *TreeNode) int {