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.
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; } };
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.