n
만큼(s
의 길이) 갖는 배열 생성s
와 indices
순회indices
의 i
번째 요소를 인덱스로 설정s
의 i
번째 요소를 현재 문자로 설정function restoreString(s: string, indices: number[]): string {
const n = s.length
const shuffled = Array(n)
for(let i = 0; i < n; i++) {
const idx = indices[i]
const char = s[i]
shuffled[idx] = char
}
return shuffled.join('')
};