TreeNode constructSubTree(int[] preorder, int preBegin, int preEnd,
                int[] inorder, int inBegin, int inEnd) {
            int rootValue = preorder[preBegin];
            int rootIndex = find(inorder, rootValue);
            if (rootIndex == -1 || rootIndex < inBegin || rootIndex > inEnd)
                return null;

            TreeNode root = new TreeNode(rootValue);

            if (rootIndex != inBegin) {
                root.left = constructSubTree(preorder, preBegin + 1, preBegin
                        + rootIndex - inBegin - 1, inorder, inBegin,
                        rootIndex - 1);
            }

            if (rootIndex != inEnd) {
                root.right = constructSubTree(preorder, preBegin + rootIndex
                        - inBegin + 1, preEnd, inorder, rootIndex + 1, inEnd);
            }

            return root;
        }