I don't know why my code can't be accepted?


  • 1
    5
    /**
    
    • Definition for binary tree

    • struct TreeNode {

    • int val;
      
    • TreeNode *left;
      
    • TreeNode *right;
      
    • TreeNode(int x) : val(x), left(NULL), right(NULL) {}
      
    • };
      */
      class Solution {
      public:
      bool isValidBST(TreeNode *root) {
      if(!root)
      return true;

       if(root->left)
           isValidBST(root->left);
      
      static int tmp = root->val;
      static int flag = 0;
      if(flag == 0){
          tmp = root->val;
          flag = 1;
      }else if(tmp>=root->val)
           return false;
       else
           tmp = root->val;
           
       if(root->right)
           isValidBST(root->right);
           
       return true;
      

      }
      };

    I write a test case and run this code in my own compiling environment, the result is correct, but I do not know why it can not be accepted.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.