Runtime error on OJ, but works fine locally


  • 0
    M

    Keep getting runtime error even for [-1] [-1]. But runs fine locally. Anyone throw some light?

    class Solution {
    public:
        TreeNode *recursiveBuilder(int inorder[], int postorder[], int n) {
            if (n==0) return NULL;
    
            int rootval = postorder[n-1];
            TreeNode temp(rootval);
            TreeNode *root = &temp;
            int i = 0;
            while (inorder[i]!=rootval) ++i;
            root->left = recursiveBuilder(inorder, postorder, i);
            root->right = recursiveBuilder(inorder+i+1, postorder+i, n-i-1);
            return root;
        }
        TreeNode *buildTree(vector<int> &inorder, vector<int> &postorder) {
            return recursiveBuilder(&inorder[0], &postorder[0], inorder.size());
        }
    };

Log in to reply
 

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