Getting runtime error - surprising


  • 0
    V

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

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

  • 0
    X

    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.