1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| func isValidBST(root *TreeNode) bool { return dfs(root, math.MinInt64, math.MaxInt64) }
func dfs(root *TreeNode, min int, max int) bool { if root == nil { return true }
if root.Val >= max || root.Val <= min { return false } return dfs(root.Left, min, root.Val) && dfs(root.Right, root.Val, max) }
|