Sort an array using merge sort
Intuition\n I thought of solving using merge sort using O(nlogn) complexity \n\n# Approach\n Merge sort \n\n# Complexity\n- Time complexity:\n O(nlogn) \n\n- Sp
# Intuition\n<!-- I thought of solving using merge sort using O(nlogn) complexity -->\n\n# Approach\n<!-- Merge sort -->\n\n# Complexity\n- Time complexity:\n<!-- O(nlogn) -->\n\n- Space complexity:\n<!-- O(logn) -->\n\n# Code\n```\nclass Solution {\n    public int[] sortArray(int[] nums) {\n        if(nums.length==1){\n            return nums;\n        }\n        int mid=nums.length/2;\n        int[] left=sortArray(Arrays.copyOfRange(nums,0,mid));\n        int[] right=sortArray(Arrays.copyOfRange(nums,mid,nums.length));\n        return merge(left,right);\n    }\n    static int[] merge(int[] first,int[] last){\n        int[] mix=new int[first.length+last.length];\n        int i=0,j=0,k=0;\n        while(i<first.length && j<last.length){\n            if(first[i]<last[j]){\n                mix[k]=first[i];\n                i++;\n            }else{\n                mix[k]=last[j];\n                j++;\n            }\n            k++;\n        }\n        while(i<first.length){\n            mix[k]=first[i];\n            i++;\n            k++;\n        }\n        while(j<last.length){\n            mix[k]=last[j];\n            j++;\n            k++;\n        }\n        return mix;\n    } \n}\n```
['Divide and Conquer', 'Merge Sort', 'Java']