struct TreeNode* buildTree(int* inorder, int inorderLen, int* postorder, int postorderLen ) {
// write code here
if(inorderLen==0){
return NULL;
}
struct TreeNode* head=(struct TreeNode*)malloc(sizeof(struct TreeNode));
head->val=postorder[postorderLen-1];
int k=0;
int left_length=0;
int right_length=0;
while(postorder[postorderLen-1]!=inorder[k]){
k++;
}
left_length=k;
right_length=inorderLen-k-1;
head->left=buildTree(inorder, left_length, postorder, left_length);
head->right=buildTree(inorder+k+1, right_length, postorder+k, right_length);
return head;
}