- Date : 2021.07.11(일)
- Time : 15분
- Given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled string.
- s.length == indices.length == n
- 1 <= n <= 100
- s contains only lower-case English letters.
- 0 <= indices[i] < n
- All values of indices are unique (i.e. indices is a permutation of the integers from 0 to n - 1).
- Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3]
- Output: "leetcode"
- Explanation: As shown, "codeleet" becomes "leetcode" after shuffling.
def restoreString(self, s: str, indices: List[int]) -> str:
mylist = [""] * len(s)
i = 0
for j in indices:
mylist[j] = s[i]
i += 1
return "".join(mylist)
: 먼저 문자열의 길이만큼 배열을 생성해준다. 그리고 indices를 기준으로 하나씩 빼면서 원래의 문자열에 있던 문자열을 가져와준다.