Getting runtime error - surprising

  • 0

    Can Any one tell why am I getting runtime error for this simple code. It runs perfectly in my local compiler.

    class Solution {
        TreeNode *buildTree(vector<int> &preorder, vector<int> &inorder) {
        TreeNode *root;
        return root;

  • 0

    You code returns an uninitialized pointer, while the system tries to evaluate whether it is a correct tree or not, it will throw a runtime error if it tries to access its left or right child.

Log in to reply

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