mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
Update 0098.验证二叉搜索树.md
This commit is contained in:
@ -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)
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user