sundeepblue
4/12/2014 - 2:13 AM

is valid binary search tree. validate BST

is valid binary search tree. validate BST

bool is_valid_BST(TreeNode *root) {
    if(!root) return true;
    return helper(root, INT_MIN, INT_MAX);
}

bool helper(TreeNode *root, int L, int R) {
    if(!root) return true;
    if(root->val <= L || root->val >= R) 
        return false;
    return helper(root->left, L, root->val) && helper(root->right, root->val, R);
}