Restore the String
Sometimes data arrives shuffled, but you also get a clue telling where each item belongs. Write a function restore_string that receives a string s and a list indices of the same length. The character at position i in s must move to position indices[i] in the new string. Return the restored string.
Примеры
Ввод
"codeleet", [4, 5, 6, 7, 0, 2, 1, 3]Вывод
"leetcode"Ввод
"abc", [0, 1, 2]Вывод
"abc"Ввод
"aiohn", [3, 1, 4, 2, 0]Вывод
"nihao"Нужно реализовать
def restore_string(s: str, indices: list[int]) -> str:
Теги
stringsarray
Jelentkezz be a beküldési előzmények megtekintéséhez
BejelentkezésJelentkezz be az MI-mentor használatához
BejelentkezésVisible tests
1
Input
"codeleet", [4,5,6,7,0,2,1,3]Expected
"leetcode"2
Input
"abc", [0,1,2]Expected
"abc"3
Input
"aiohn", [3,1,4,2,0]Expected
"nihao"4
Input
"art", [1,0,2]Expected
"rat"5
Input
"a", [0]Expected
"a"6
Input
"wxyz", [3,2,1,0]Expected
"zyxw"Focus radio
Paused · SomaFM · Fluid