Java QuickSort + SelectionSort + MergeSort summary
https://leetcode.com/submissions/detail/222979198/\n\nclass Solution {\n    \n    private static final int QUICKSORTSHOLD = 50;\n    private static final int ME
https://leetcode.com/submissions/detail/222979198/\n```\nclass Solution {\n    \n    private static final int QUICKSORTSHOLD = 50;\n    private static final int MERGESORTSHOLD = 300;\n    \n    public int[] sortArray(int[] nums) {\n        if (nums == null || nums.length < 2){\n            return nums;\n        }\n        \n        if (nums.length < QUICKSORTSHOLD){\n            selectionSort(nums);   \n        }else if (nums.length < MERGESORTSHOLD) {\n            quickSort(nums);\n        }else{\n            mergeSort(nums);\n        }\n        return nums;\n    }\n    \n    private void selectionSort(int[] nums){\n        for (int i = 0; i < nums.length; i++){\n            int minIndex = i;\n            for (int j = i + 1; j < nums.length; j++){\n                if (nums[j] < nums[minIndex]){\n                    minIndex = j;\n                }\n            }\n            exch(nums, i, minIndex);\n        }\n    }\n    \n    private void quickSort(int[] nums){\n        quickSort(nums, 0, nums.length - 1);\n    }\n    \n    private void quickSort(int[] nums, int lo, int hi){\n        if (lo >= hi)\n            return ;\n        int pivot = partition(nums, lo, hi);\n        quickSort(nums, lo, pivot - 1);\n        quickSort(nums, pivot + 1, hi);\n    }\n    \n    private int partition(int[] nums, int lo, int hi){\n        int q = lo + (int)(Math.random() * (hi - lo + 1));\n        exch(nums, lo, q);\n        \n        int index = lo + 1;\n        for (int i = lo + 1; i <= hi; i++){\n                if (nums[i] < nums[lo]){\n                    exch(nums, i, index++);\n                }\n        }\n        exch (nums, lo, --index);\n        return index;\n    }\n    \n    private void mergeSort(int[] nums){\n        mergeSort(nums, 0, nums.length - 1);\n    }\n    \n    private void mergeSort(int[] nums, int lo, int hi){\n        if (lo >= hi)\n            return ;\n        int mid = (lo + hi) >>> 1;\n        mergeSort(nums, lo, mid);\n        mergeSort(nums, mid + 1, hi);\n        merge(nums, lo, mid, mid + 1, hi);\n    }\n    \n    private void merge(int[] nums, int preLo, int preHi, int endLo, int endHi){\n        if (preLo == endHi)\n            return;\n        int lo = preLo;\n        int hi = endHi;\n        \n        int[] newArr = new int[preHi - preLo + 1 + endHi - endLo + 1];\n        int index = 0;\n        while (preLo <= preHi && endLo <= endHi){\n            newArr[index++] = (nums[preLo] < nums[endLo]) ? nums[preLo++] : nums[endLo++];\n        }\n        while (preLo <= preHi){\n            newArr[index++] = nums[preLo++];\n        }\n        while (endLo <= endHi){\n            newArr[index++] = nums[endLo++];\n        }\n        \n        index = 0;\n        while (lo <= hi){\n            nums[lo++] = newArr[index++];\n        }\n    }\n    \n    private void exch(int[] nums, int i, int j){\n        if (i == j)\n            return;\n        nums[i] ^= nums[j];\n        nums[j] ^= nums[i];\n        nums[i] ^= nums[j];\n    }\n    \n}\n```
[]