문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
문자열 s와 같은 길이의 정수 배열 indices가 주어진다. 문자열 s는 i번째 위치의 문자가 섞인 문자열에서 indices[i]로 이동하도록 섞인다.
섞인 문자열을 반환해라.
#1
Input: s = "codeleet", indices = [4, 5, 6, 7, 0, 2, 1, 3]
Output: "leetcode"
Explanation: "codeleet"는 섞인 후 "leetcode"가 된다.
#2
Input: s = "abc", indices = [0, 1, 2]
Output: "abc"
Explanation: 섞인 후 각 문자들은 그 자리에 있다.
class Solution {
public String restoreString(String s, int[] indices) {
int n = s.length();
char[] c = new char[n];
for(int i = 0; i < n; i++){
c[indices[i]] = s.charAt(i);
}
return new String(c);
}
}