https://leetcode-cn.com/problems/validate-binary-search-tree/
//思路:中序遍历,升序
var preNode : TreeNode?
func isValidBST(_ root: TreeNode?) -> Bool {
if root == nil {return true}
if !isValidBST(root?.left) {return false}
if (preNode != nil) && preNode!.val >= root!.val {return false}
preNode = root
if !isValidBST(root?.right) {return false}
return true
}
网友评论