1// We know inorder traversal of BST is always sorted, so we are just finding2// inorder traversal and check whether it is in sorted manner or not, but only3// using const space using prev pointer.4class Solution {5public:6TreeNode *prev;7Solution() {8prev = NULL;9}10bool isValidBST(TreeNode *root) {11if (root == NULL) return true;12bool a = isValidBST(root->left);13if (!a) return false;14if (prev != NULL) {15if (prev->val >= root->val) return false;16}17prev = root;18return isValidBST(root->right);19}20};