/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class Solution { private: vector<int> inorder; public: bool isValidBST(TreeNode *root) { // Start typing your C/C++ solution below // DO NOT write int main() function if(root==NULL) return true; inorder.clear(); InOrder(root); for(int i = 1;i < inorder.size();i++) { if(inorder[i] <= inorder[i-1]) return false; } return true; } void InOrder(TreeNode *root) { if(root==NULL) return; InOrder(root->left); inorder.push_back(root->val); InOrder(root->right); } };