LeetCode:654
    给定一个不含重复元素的整数数组 nums 。一个以此数组直接递归构建的 最大二叉树 定义如下:

    二叉树的根是数组 nums 中的最大元素。
    左子树是通过数组中 最大值左边部分 递归构造出的最大二叉树。
    右子树是通过数组中 最大值右边部分 递归构造出的最大二叉树。
    返回有给定数组 nums 构建的 最大二叉树 。

    1. class Solution {
    2. public TreeNode constructMaximumBinaryTree(int[] nums) {
    3. return build(nums, 0, nums.length - 1);
    4. }
    5. private TreeNode build(int[] nums, int i, int j) {
    6. if (j < i){
    7. return null;
    8. }
    9. int index = i;
    10. for (int k = i + 1; k < j + 1; k++) {
    11. if (nums[index] < nums[k]){
    12. index = k;
    13. }
    14. }
    15. TreeNode node = new TreeNode(nums[index]);
    16. node.left = build(nums, i, index - 1);
    17. node.right = build(nums, index + 1, j);
    18. return node;
    19. }
    20. }