A better Python solution
Here I copied the previous top voted Python solution:\n\nclass Solution:\n    def buildTree(self, inorder, postorder):\n        if not inorder or not postorder:
Here I copied the previous top voted Python solution:\n```\nclass Solution:\n    def buildTree(self, inorder, postorder):\n        if not inorder or not postorder:\n            return None\n        \n        root = TreeNode(postorder.pop())\n        inorderIndex = inorder.index(root.val) # Line A\n\n        root.right = self.buildTree(inorder[inorderIndex+1:], postorder) # Line B\n        root.left = self.buildTree(inorder[:inorderIndex], postorder) # Line C\n\n        return root\n```\n\nThe code is clean and short. However, if you give this implementation during an interview, there is a good chance you will be asked, "can you improve/optimize your solution?"\n\nWhy? Take a look at Line A, Line B and Line C.\nLine A takes O(N) time.\nLine B and C takes O(N) time and extra space.\nThus, the overall running time and extra space is O(N^2).\nSo this implementation has a very bad performance, and you can avoid it.\n\nHere is my solution which has O(N) time and extra space.\n```\nclass Solution:\n    def buildTree(self, inorder, postorder):\n        map_inorder = {}\n        for i, val in enumerate(inorder): map_inorder[val] = i\n        def recur(low, high):\n            if low > high: return None\n            x = TreeNode(postorder.pop())\n            mid = map_inorder[x.val]\n            x.right = recur(mid+1, high)\n            x.left = recur(low, mid-1)\n            return x\n        return recur(0, len(inorder)-1)\n```
[]