```
class Solution {
public:
bool isValidBST(TreeNode * root) {
if(root==NULL)return true;
if(root->left=NULL && root->right==NULL)return true;
return dfs(root,LONG_MIN,LONG_MAX);
}
private:
bool dfs(TreeNode * root,long low,long high)
{
if(root==NULL)return true;
return (root->val > low) && (root->val < high) && dfs(root->left,low,root->val) && dfs(root->right,root->val,high);
}
};
```