```
class Solution {
public:
TreeNode *buildTree(vector<int> &preorder, vector<int> &inorder)
{
TreeNode* root=buildTree1(preorder,inorder,0,preorder.size()-1,0,inorder.size()-1);
return root;
}
TreeNode *buildTree1(vector<int> &preorder, vector<int> &inorder, int prestart,int preend, int instart, int inend)
{
if(preend<=preorder.size() -1 &&prestart>=0 && inend<=inorder.size() -1 &&instart>=0 && prestart<=preend && instart<=inend)
{
TreeNode* root=new TreeNode(preorder[prestart]);
int i;
for(i=instart;i<=inend;i++)
{
if(inorder[i]==preorder[prestart])
break;
}
root->left=buildTree1(preorder,inorder,prestart+1,prestart+i, instart,instart+i-1);
root->right=buildTree1(preorder,inorder,prestart+i+1,preend,instart+i+1,inend);
return root;
}
else
return NULL;
}
};
```

Why OLE? Is recurve solution cost too much stack, so it should be memory limit exceeded....I think, I think

recursive is the simplest one solution