validate-binary-search-tree

2019-05-28  本文已影响0人  DaiMorph
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);
    }
};
上一篇 下一篇

猜你喜欢

热点阅读