title: Check is binary tree is bst or not
body: <p>Why this code is not passing all test cases.can anyone help??</p>
  
  <pre><code>class Solution {
  public:
  
      int x=1,prev=INT_MIN;
      void bst(struct TreeNode *root){
          if(root==NULL){
              return;
          }
          bst(root-&gt;left);
          if(root-&gt;val&lt;=prev){
              x=0;
          }
          prev=root-&gt;val;
          bst(root-&gt;right);
       }
         bool isValidBST(TreeNode* root) {
             bst(root);
             if(x==1){
                 return true;
             }else{
                 return false;
             }
       }
  
  };
  </code></pre>