Merge-sort bottom-up Java
Have not found the bottom-up java merge sort solution here.\n\n\nclass Solution {\n\n    public int[] sortArray(int[] nums) {\n        // starting from nums.len
Have not found the bottom-up java merge sort solution here.\n\n```\nclass Solution {\n\n    public int[] sortArray(int[] nums) {\n        // starting from nums.length arrays of size 1 (already sorted)\n        // on each step merge two adjacent sorted arrays so that they remain sorted\n        // you may notice that sizes of arrays doubles on each step\n        for(int currSize = 1; currSize < nums.length; currSize *= 2) {\n            // on each step we need to merge/sort two adjacent arrays\n            // we calculate the start index of this pair and call merge function\n            for(int start = 0; start < nums.length; start += 2*currSize) {\n                merge(nums, start, start + currSize, start + 2*currSize);\n            }\n        }\n        \n        return nums;\n    }\n    \n    // merge two sorted adjacent arrays\n    // first array (start, ..., mid-1) and second array (mid, ..., end-1)\n    private void merge(int[] nums, int start, int mid, int end) {\n        // need to check for cases when second array do not fully fits in the source array \n        if (end > nums.length) end = nums.length;\n        // need to check for cases when the first array just partially fits in the source array\n        if (mid >= end) return;\n        int[] nums2 = new int[end-mid];\n        for(int i=0;i<nums2.length;i++) nums2[i] = nums[mid+i];\n        \n        int i = mid-1, j = nums2.length-1, k = end-1;\n        while(i >= start && j >= 0) {\n            if (nums[i] > nums2[j]) {\n                nums[k--] = nums[i--];\n            } else {\n                nums[k--] = nums2[j--];\n            }\n        }\n        \n        while(i>=start) nums[k--] = nums[i--];\n        while(j>=0) nums[k--] = nums2[j--];        \n    }\n    \n}\n```
['Merge Sort', 'Java']