Insert in Given Order
Sometimes you need to build a list with precise insertions instead of simply appending to the end. Given two lists of the same length, nums contains the values and index contains the positions where they should be inserted. Go from left to right, insert nums[i] at position index[i], shift later elements to the right, and return the final list.
Примеры
Ввод
[0, 1, 2, 3, 4], [0, 1, 2, 2, 1]Вывод
[0, 4, 1, 3, 2]Ввод
[1, 2, 3, 4, 0], [0, 1, 2, 3, 0]Вывод
[0, 1, 2, 3, 4]Ввод
[1], [0]Вывод
[1]Нужно реализовать
def create_target_array(nums: list[int], index: list[int]) -> list[int]:
Теги
array
Logi sisse, et näha esituste ajalugu
Logi sisseLogi sisse, et kasutada AI mentorit
Logi sisseVisible tests
1
Input
[0,1,2,3,4], [0,1,2,2,1]Expected
[0,4,1,3,2]2
Input
[1,2,3,4,0], [0,1,2,3,0]Expected
[0,1,2,3,4]3
Input
[1], [0]Expected
[1]4
Input
[5,5,5], [0,0,0]Expected
[5,5,5]5
Input
[1,2,3], [0,0,0]Expected
[3,2,1]6
Input
[1], [0,0]Expected
[1]Focus radio
Paused · SomaFM · Fluid