c++ - Running on my laptop, but giving runtime error on Leetcode -


i have build tree preorder , inorder traversals. code working fine on laptop, not on leetcode. giving runtime error, suggestions ?

int findindex(vector<int>& inorder,int index) {     int size = inorder.size();     for(int i=0;i<size;i++)     {         if(index == inorder[i])                 return index;     } }  treenode* helper(vector<int>& preorder, vector<int>& inorder, int start, int end) {     static int preindex = 0;     if(start > end)         return null;     treenode* head;     head = (treenode *)malloc(sizeof(treenode));     head->val = preorder[preindex++];     head->left = null;     head->right = null;     if(start == end)         return head;     int index = findindex(inorder,head->val);      head->left = helper(preorder, inorder,start, index-1);     head ->right = helper(preorder, inorder, index+1, end);     return head; }  treenode* solution::buildtree(vector<int> &preorder, vector<int> &inorder) {     int size = preorder.size();     if(size == 0)         return null;     return helper(preorder, inorder, 0, size-1); } 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -