| Объединение массивов |
| 1 | def merge(self, nums1, m, nums2, n) -> None: |
| 2 | a = m - 1 |
| 3 | b = n - 1 |
| 4 | c = m + n - 1 |
| 5 | while a >= 0 and b >= 0: |
| 6 | if nums1[a] > nums2[b]: |
| 7 | nums1[c] = nums1[a] |
| 8 | a -= 1 |
| 9 | else: |
| 10 | nums1[c] = nums2[b] |
| 11 | b -= 1 |
| 12 | c -= 1 |
| 13 | if b >= 0: |
| 14 | nums1[:b + 1] = nums2[:b + 1] |
| 15 |
Комментарии