530. 二叉搜索树的最小绝对差

中序遍历递归实现
var pre *TreeNodevar res intfunc dfs(root *TreeNode){if root==nil{return}dfs(root.Left)if pre!=nil {res = int(math.Min(math.Abs(float64(root.Val-pre.Val)),float64(res)))}pre = rootdfs(root.Right)}func getMinimumDifference(root *TreeNode) int {res = math.MaxInt32dfs(root)return res}func main() {root :=&TreeNode{Val: 1}two :=&TreeNode{Val: 2}three :=&TreeNode{Val: 3}root.Right = threethree.Left = twofmt.Println(getMinimumDifference(root))}

