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.
"""
index = m+n-1
while m-1>= 0 and n-1 >= 0:
if nums1[m-1] < nums2[n-1]:
nums1[index] = nums2[n-1]
n-= 1
index -= 1
else:
nums1[index] = nums1[m-1]
m-= 1
index -= 1
nums1[:n] = nums2[:n]
Leetcode 88. Merge Sorted Array
最新推荐文章于 2022-10-19 10:44:55 发布