public SubArray byDivideAndConquer(int nums[], int left, int right) {

    if (left == right) {
      return new SubArray(left, right, nums[left]);
    } else {
      int mid = (left + right) / 2;
      SubArray leftMax = byDivideAndConquer(nums, left, mid);
      SubArray rightMax = byDivideAndConquer(nums, mid + 1, right);

      //Find max array crossing mid
      int leftCrossMaxSum = nums[mid];
      int sum = 0;
      int crossLeft = mid;
      int crossRight = mid + 1;
      for (int i = mid; i >= left; i--) {
        sum += nums[i];
        if (sum > leftCrossMaxSum) {
          leftCrossMaxSum = sum;
          crossLeft = i;
        }
      }
      int rightCrossMaxSum = nums[mid + 1];
      sum = 0;
      for (int j = mid + 1; j <= right; j++) {
        sum += nums[j];
        if (sum > rightCrossMaxSum) {
          rightCrossMaxSum = sum;
          crossRight = j;
        }
      }
      SubArray crossMax = new SubArray(crossLeft, crossRight, leftCrossMaxSum + rightCrossMaxSum);

      if (leftMax.getMax() > rightMax.getMax() && leftMax.getMax() > crossMax.getMax()) {
        return leftMax;
      } else if (rightMax.getMax() > leftMax.getMax() && rightMax.getMax() > crossMax.getMax()) {
        return rightMax;
      } else {
        return crossMax;
      }

    }
  }