> For the complete documentation index, see [llms.txt](https://zcjian.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zcjian.gitbook.io/project/array/merge-sorted-array.md).

# Merge Sorted Array

LeetCode 88

```python
class Solution:
    def merge(self, nums1, m, nums2, n):
        """
        :type nums1: List[int]
        :type m: int
        :type nums2: List[int]
        :type n: int
        :rtype: void Do not return anything, modify nums1 in-place instead.
        """
        """
               +n
        [1,2,0,3,5,6] m = 3
          m-1
        [2,5,6] n = 3
        n-1
        """
        while m > 0 and n > 0:
            print(nums1[m-1])
            print(nums2[n-1])

            if nums1[m-1] < nums2[n-1]:
                nums1[m-1+n] = nums2[n-1]
                n = n - 1
            else:
                nums1[m-1+n], nums1[m-1] = nums1[m-1], nums1[m-1+n]
                m = m - 1
        """
        [0] m = 0
        [1] n = 1
        """
        if m == 0 and n > 0:
            nums1[:n] = nums2[:n]
```
