Merge Sort

语言

Implement a function that performs a recursive merge sort. The function should be recursive and takes in an array of integers. The output should be an array with the input sorted in ascending order.

The input array may be empty and may contain negative or duplicate integers.

Recursive Merge Sort expected input and output

Examples

mergeSort([9, 3, 6, 2, 1, 11]); // [1, 2, 3, 6, 9, 11]
mergeSort([12, 16, 14, 1, 2, 3]); // [1, 2, 3, 12, 14, 16]

Hints

加载编辑器

    Merge Sort | 算法面试题及解决方案