/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */import"math"funcminDiffInBST(root *TreeNode) int { result, previous := math.MaxInt16, -1 getMinDiffHelper(root, &result, &previous)return result}funcgetMinDiffHelper(root *TreeNode, res, prev *int) {if root ==nil {return } getMinDiffHelper(root.Left, res, prev)if*prev !=-1 {*res =min(*res, abs(root.Val -*prev)) }*prev = root.Val getMinDiffHelper(root.Right, res, prev)}funcmin(x, y int) int {if x > y {return y }return x}funcabs(x int) int {if x >=0 {return x }return-x}