Test case [0,-1] failed when trying static variable solution

  • 0
    bool isValidBST(TreeNode* root) {
      if (!root) return true;
      if (!isValidBST(root->left)) return false;
      static long pre=LONG_MIN;
      if (pre>=(long)root->val) return false;
      pre = root->val;
      return isValidBST(root->right);

    I suppose [0,-1] is:


    which works in my environment. Why it fails in OJ?

  • 1

    Did you read the FAQ? You would have to reset your static variable as the static variable preserves its value between test cases.

Log in to reply

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