@@ -0,0 +1,1602 @@
+/**%0A * Definition for a binary tree node.%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode() %7B%7D%0A *     TreeNode(int val) %7B this.val = val; %7D%0A *     TreeNode(int val, TreeNode left, TreeNode right) %7B%0A *         this.val = val;%0A *         this.left = left;%0A *         this.right = right;%0A *     %7D%0A * %7D%0A */%0Aclass Solution %7B%0A    public TreeNode buildTree(int%5B%5D preorder, int%5B%5D inorder) %7B%0A        Map%3CInteger, Integer%3E inorderIdx = new HashMap%3C%3E();%0A        for(int i = 0; i %3C inorder.length; i++) %7B%0A            inorderIdx.put(inorder%5Bi%5D, i);%0A        %7D%0A%0A        return buildTree(preorder, 0, preorder.length, inorderIdx, 0, inorder.length);%0A    %7D%0A%0A    public TreeNode buildTree(int%5B%5D preorder, int preStart, int preEnd, Map%3CInteger, Integer%3E inorderIdx, int inStart, int inEnd) %7B%0A        // System.out.printf(%22preStart: %25d, preEnd: %25d, inStart: %25d, inEnd: %25d%5Cn%22, preStart, preEnd, inStart, inEnd);%0A%0A        if (preStart %3E= preEnd) %7B%0A            return null;%0A        %7D%0A%0A        TreeNode root = new TreeNode(preorder%5BpreStart%5D);%0A        int rootIdx = inorderIdx.get(root.val);%0A        int leftNum = rootIdx - inStart;%0A        int leftStart = preStart + 1;%0A        int leftEnd = leftStart  + leftNum;%0A        TreeNode left = buildTree(preorder, leftStart, leftEnd, inorderIdx, inStart, rootIdx);%0A%0A        %0A        int rightStart = leftEnd;%0A        int rightEnd = preEnd;%0A        TreeNode right = buildTree(preorder, rightStart, rightEnd, inorderIdx, rootIdx + 1, inEnd);%0A%0A        root.left = left;%0A        root.right = right;%0A        return root;%0A    %7D%0A%7D %0A

Create ConstructBinaryTree.java