从中序遍历和后序遍历构建二叉树
class Solution { public HashMapmap = new HashMap<>(); public TreeNode buildTree(int[] inorder, int[] postorder) { int len = postorder.length; for(int i=0;i end) { return null; } TreeNode root = new TreeNode(preorder[last]); int middle = map.get(preorder[last]); root.left = buildTree2(preorder,inorder,start,middle-1,last-1-(end-middle)); root.right = buildTree2(preorder,inorder,middle+1,end,last-1); return root; }}