title: Merge Sorted Array in leetcode
body: <p>i saw this in <a href="https://leetcode.com/problems/merge-sorted-array/description/" rel="nofollow noreferrer">https://leetcode.com/problems/merge-sorted-array/description/</a> and the answer in <a href="https://leetcode.com/problems/merge-sorted-array/discuss/29503/Beautiful-Python-Solution" rel="nofollow noreferrer">https://leetcode.com/problems/merge-sorted-array/discuss/29503/Beautiful-Python-Solution</a></p>
  
  <pre><code>def merge(self, nums1, m, nums2, n):
          while m &gt; 0 and n &gt; 0:
              if nums1[m-1] &gt;= nums2[n-1]:
                  nums1[m+n-1] = nums1[m-1]
                  m -= 1
              else:
                  nums1[m+n-1] = nums2[n-1]
                  n -= 1
          if n &gt; 0:
              nums1[:n] = nums2[:n]
  </code></pre>
  
  <p>I have two doubts:</p>
  
  <ol>
  <li>When i want to run the code <code>print(Solution().merge([1, 2, 3], 3,
  [4, 5, 6], 3))</code> and it just gave me an error hint <code>IndexError: list
  assignment index out of range</code>.</li>
  <li>I don't quite understand the methodology in the answer above.
  Could someone tell me how to solve this kind of problem?</li>
  </ol>