不能通过 当元素中 有 val == INT_MAX 或者 val == INT_MIN
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { public: bool isValidBST(TreeNode* root) { if(root==NULL) return true; return isv(root,INT_MIN,INT_MAX); } bool isv(TreeNode * root , int min ,int max) { if(root==NULL) return true; if(root->left!=NULL &&( root->val<= root->left->val||root->left->val<=min)) return false; if(root->right!=NULL&&( root->val>=root->right->val||root->right->val>=max)) return false; return isv(root->left,min,root->val)&&isv(root->right,root->val,max); } };