标签:des style http color io os ar sp div
Given a binary tree, determine if it is a valid binary search tree (BST).
Assume a BST is defined as follows:
bool isValidBST(TreeNode *root) {
if(!root) return true;
TreeNode *right_most = root->left, *left_most = root->right;
while(right_most && right_most->right){
right_most = right_most->right;
}
while(left_most && left_most->left){
left_most = left_most->left;
}
return isValidBST(root->left) && isValidBST(root->right)
&& (!right_most || right_most->val < root->val)
&& (!left_most || root->val < left_most->val);
}
leetcode dfs Validate Binary Search Tree
标签:des style http color io os ar sp div
原文地址:http://blog.csdn.net/zhengsenlie/article/details/40018467