美文网首页
validate-binary-search-tree

validate-binary-search-tree

作者: DaiMorph | 来源:发表于2019-05-28 10:11 被阅读0次
class Solution {
public:
    bool isValidBST(TreeNode *root) {
        return judge(root,INT_MIN,INT_MAX);
    }
    bool judge(TreeNode*root,int low,int high)
    {
        if(root==NULL)return true;
        return root->val>low&&root->val<high&&judge(root->left,low,root->val)&&judge(root->right,root->val,high);
    }
};

网友评论

      本文标题:validate-binary-search-tree

      本文链接:https://www.haomeiwen.com/subject/gkrltctx.html