mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
update 0530.二叉搜索树的最小绝对差: 删除 go 冗余代码
This commit is contained in:
@ -248,28 +248,6 @@ class Solution:
|
||||
## 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
|
||||
// 中序遍历的同时计算最小值
|
||||
func getMinimumDifference(root *TreeNode) int {
|
||||
|
Reference in New Issue
Block a user