题目:
题解:
class Solution:def merge(self, nums1: List[int], m: int, nums2: List[int], n: int) -> None:"""Do not return anything, modify nums1 in-place instead."""p1, p2 = m - 1, n - 1tail = m + n - 1while p1 >= 0 or p2 >= 0:if p1 == -1:nums1[tail] = nums2[p2]p2 -= 1elif p2 == -1:nums1[tail] = nums1[p1]p1 -= 1elif nums1[p1] > nums2[p2]:nums1[tail] = nums1[p1]p1 -= 1else:nums1[tail] = nums2[p2]p2 -= 1tail -= 1