Golang | Leetcode Golang题解之第530题二叉搜索树的最小绝对差
题目:
题解:
func getMinimumDifference(root *TreeNode) int {ans, pre := math.MaxInt64, -1var dfs func(*TreeNode)dfs = func(node *TreeNode) {if node == nil {return}dfs(node.Left)if pre != -1 && node.Val-pre < ans {ans = node.Val - pre}pre = node.Valdfs(node.Right)}dfs(root)return ans
}