😎풀이

  1. 크기를 n만큼(s의 길이) 갖는 배열 생성
  2. sindices 순회
    2-1. indicesi 번째 요소를 인덱스로 설정
    2-2. si 번째 요소를 현재 문자로 설정
    2-3. 인덱스에 문자 할당
  3. 배열 문자열 형태로 변환하여 반환
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('')
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글