leetCode 문제풀이 1528번 Shuffle String

devmomo·2021년 3월 11일
0

알고리즘

목록 보기
15/52
post-thumbnail

1528. Shuffle String

문제
문자열 데이터 s와 정수로 이루어진 배열 indices가 매개변수로 주어질 때,
indices[i]를 인덱스로 하는 새로운 문자열을 리턴하는 함수 짜기
가정
1. 문자열 s와 배열 indices의 길이는 n으로 동일
2. n은 1이상 100이하
3. 문자열 s는 영문 소문자로만 이루어짐
4. indices[i]는 0 이상 n이하
5. indices의 모든 원소는 유일함
풀이

var restoreString = function(s, indices) {
    const result = Array.from({length:s.length}).fill(0);
    indices.forEach((data,index)=>result[data]=[...s][index]);
    return result.join('');
};
profile
FE engineer

0개의 댓글