문제풀이 2021 01 24
2021.01.24 연습
- 사용언어 : java
class Solution {
public String restoreString(String s, int[] indices) {
StringBuilder result = new StringBuilder();
char[] arrSb = new char[s.length()];
char[] arr = s.toCharArray();
int count = 0;
for (int i : indices) {
arrSb[i] = arr[count];
count++;
}
for (char c : arrSb) {
result.append(c);
}
return result.toString();
}
}
Runtime: 1 ms, faster than 99.93% of Java online submissions for Shuffle String. Memory Usage: 39 MB, less than 78.01% of Java online submissions for Shuffle String.
- 다른코드 참고
//N = size of input string
//Time Complexity: O(N)
//Space Complexity: O(1)
public String restoreString(String s, int[] indices) {
char[] ch = new char[s.length()];
for (int i = 0;i < s.length();i++) {
ch[indices[i]] = s.charAt(i);
}
return String.valueOf(ch);
}