Merge Sort
Given an integer array nums, return its values in ascending order by using merge sort. Merge sort recursively splits the array until each range contains one…
Given an integer array `nums`, return its values in ascending order by using merge sort. Merge sort recursively splits the array until each range contains one value. It then stably merges sorted halves. When two front values are equal, take the value from the left half first.
- `1 <= nums.length <= 10^4` - `-10^6 <= nums[i] <= 10^6`
Example 1: input nums = [38,27,43,3,9,82,10]; output [3,9,10,27,38,43,82]. Single-value ranges merge into sorted pairs and then into larger sorted ranges.
Example 2: input nums = [2,1]; output [1,2]. The two one-value halves merge by taking 1 before 2.
Category: Sorting. Topic: sorting-searching. Difficulty: Medium. Patterns: divide-and-conquer, sorting.