Merge pull request #62 from QuinnDK/添加0098验证二叉搜索树Go版本

添加0098验证二叉搜索树 Go版本
This commit is contained in:
Carl Sun
2021-05-13 17:27:17 +08:00
committed by GitHub

View File

@ -260,7 +260,25 @@ Python
Go
```Go
import "math"
func isValidBST(root *TreeNode) bool {
if root == nil {
return true
}
return isBST(root, math.MinInt64, math.MaxFloat64)
}
func isBST(root *TreeNode, min, max int) bool {
if root == nil {
return true
}
if min >= root.Val || max <= root.Val {
return false
}
return isBST(root.Left, min, root.Val) && isBST(root.Right, root.Val, max)
}
```