You are given two lists, nums1 and nums2, each sorted from small to large (equal values are allowed). The numbers m and n tell how many real values nums1 and nums2 hold.
Merge them into one sorted list. Do not return a new list. Instead, store the result inside nums1. To make room, nums1 has length m + n: its first m places hold real values, and its last n places are filled with 0 and must be ignored. The list nums2 has length n.
Examples
Example 1:
Input: nums1 = [4,5,9,0,0,0], m = 3, nums2 = [1,6,10], n = 3
Output: [1,4,5,6,9,10]
Explanation: The real values are [4,5,9] and [1,6,10]. Merged and sorted, they fill nums1 as [1,4,5,6,9,10].
Example 2:
Input: nums1 = [3,0], m = 1, nums2 = [1], n = 1
Output: [1,3]
Explanation: Merge [3] and [1]. nums1 becomes [1,3].
Example 3:
Input: nums1 = [5,6,7], m = 3, nums2 = [], n = 0
Output: [5,6,7]
Explanation: nums2 is empty, so nums1 does not change.