Welcome to LeetCode Discuss.  Please read the FAQ to help yourself making the best use of Discuss.
Ask a Question
Back to Problem

Welcome to LeetCode Discuss.

This is a place to ask questions related to only OJ problems.

Please read the FAQ to help yourself making the best use of Discuss.

Getting runtime error - surprising

0 votes
167 views

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;
    }
};
closed with the note: Questions about code you've written must describe the specific problem clearly. Please read the FAQ (http://oj.leetcode.com/discuss/faq) for more info.
asked Feb 28 in Construct Binary Tree from Preorder and Inorder Traversal by vivek3 (230 points)
closed Mar 1 by 1337c0d3r

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.


...