98.M 验证二叉搜索树
思路
Code
func isValidBST(root *TreeNode) bool {
return helper(root, math.MinInt, math.MaxInt)
}
func helper(root *TreeNode, min int, max int) bool {
if root == nil {
return true
}
if root.Val <= min || root.Val >= max {
return false
}
return helper(root.Left, min, root.Val) && helper(root.Right, root.Val, max)
}Last updated