: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.
(self, nums1, m, nums2, n)
| 120 | |
| 121 | # 第三版 |
| 122 | def merge(self, nums1, m, nums2, n): |
| 123 | """ |
| 124 | :type nums1: List[int] |
| 125 | :type m: int |
| 126 | :type nums2: List[int] |
| 127 | :type n: int |
| 128 | :rtype: void Do not return anything, modify nums1 in-place instead. |
| 129 | """ |
| 130 | mn = m + n - 1 |
| 131 | |
| 132 | while m > 0 and n > 0: |
| 133 | |
| 134 | |
| 135 | if nums1[m-1] > nums2[n-1]: |
| 136 | nums1[mn] = nums1[m-1] |
| 137 | m -= 1 |
| 138 | else: |
| 139 | nums1[mn] = nums2[n-1] |
| 140 | n -= 1 |
| 141 | mn -= 1 |
| 142 | |
| 143 | if n > 0: |
| 144 | nums1[:n] = nums2[:n] |
nothing calls this directly
no outgoing calls
no test coverage detected