/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 *	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 * };
 */
#include <climits>
class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param root TreeNode类 
     * @return bool布尔型
     */
     bool helper(TreeNode*node,long long lower,long long upper)
     {
        if(!node) return true;

        if(node->val<=lower||node->val>=upper) return false;
        return helper(node->left,lower,node->val)&&helper(node->right,node->val,upper);
     }
    bool isValidBST(TreeNode* root) {
        // write code here
        return helper(root,LLONG_MIN,LLONG_MAX);
    }
};