Follow the Index
In a permutation, a value can also be used as the address of another element. Given a list nums containing values from 0 to n-1, build a new list ans using the rule ans[i] = nums[nums[i]]. Return the completed list.
Примеры
Ввод
[0, 2, 1, 5, 3, 4]Вывод
[0, 1, 2, 4, 5, 3]Ввод
[5, 0, 1, 2, 3, 4]Вывод
[4, 5, 0, 1, 2, 3]Ввод
[0]Вывод
[0]Нужно реализовать
def build_array(nums: list[int]) -> list[int]:
Теги
array
Entre para ver seu histórico de envios
EntrarEntre para usar o AI Mentor
EntrarVisible tests
1
Input
[0,2,1,5,3,4]Expected
[0,1,2,4,5,3]2
Input
[5,0,1,2,3,4]Expected
[4,5,0,1,2,3]3
Input
[0]Expected
[0]4
Input
[1,0]Expected
[0,1]5
Input
[2,0,1]Expected
[1,2,0]6
Input
[1,0,1]Expected
[0,1,0]Focus radio
Paused · SomaFM · Fluid