Update 0098.验证二叉搜索树.md

This commit is contained in:
QuinnDK
2021-05-13 10:19:25 +08:00
committed by GitHub
parent cf42d80efc
commit 645c93b688

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)
}
```