Merge Sorted Arrays
Imagine two already sorted ribbons of numbers that need to become one clean sorted ribbon. Given nums1, where only the first m elements are meaningful, and nums2 with n elements, merge those values into one sorted list of length m+n. The extra zeroes in nums1 are only space reserved for the result.
Примеры
Ввод
[1, 2, 3, 0, 0, 0], 3, [2, 5, 6], 3Вывод
[1, 2, 2, 3, 5, 6]Ввод
[1], 1, [], 0Вывод
[1]Ввод
[0], 0, [1], 1Вывод
[1]Нужно реализовать
def merge(nums1: list[int], m: int, nums2: list[int], n: int) -> list[int]:
Теги
arraytwo-pointerssorting
Prijavi se da vidiš povijest predaja
PrijavaPrijavi se da koristiš AI mentora
PrijavaVisible tests
1
Input
[1,2,3,0,0,0], 3, [2,5,6], 3Expected
[1,2,2,3,5,6]2
Input
[1], 1, [], 0Expected
[1]3
Input
[0], 0, [1], 1Expected
[1]4
Input
[4,5,6,0,0,0], 3, [1,2,3], 3Expected
[1,2,3,4,5,6]5
Input
[2,0], 1, [1], 1Expected
[1,2]6
Input
[3,2,1,0,0,0], 2, [3,6,7], -100Expected
[2,3]Focus radio
Paused · SomaFM · Fluid