validate-binary-search-tree

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->valleft,low,root->val)&&judge(root->right,root->val,high);
    }
};

你可能感兴趣的:(validate-binary-search-tree)