https://leetcode.com/problems/shuffle-string/description/
주어진 문자열 s와 각 문자의 새로운 위치를 나타내는 인덱스 리스트 indices가 있을때, indices에 지정된 대로 문자의 순서를 재배열한 후 결과 문자열을 반환하는 문제이다.


풀이
class Solution:
def restoreString(self, s: str, indices: List[int]) -> str:
# 결과를 저장할 빈 리스트를 s의 길이만큼 생성
result = [''] * len(s)
# 각 문자와 인덱스를 순회하면서 결과 리스트에 배치
for i in range(len(s)):
result[indices[i]] = s[i]
# 결과 리스트를 문자열로 변환하여 반환
return ''.join(result)
'Algorithm > 릿코드' 카테고리의 다른 글
99클럽 코테 스터디 22일차 2733. Neither Minimum nor Maximum (0) | 2024.06.20 |
---|---|
99클럽 코테 스터디 21일차 2325. Decode the Message (0) | 2024.06.20 |
99클럽 코테 스터디 19일차 1773. Count Items Matching a Rule (0) | 2024.06.17 |
99클럽 코테 스터디 18일차 2942. Find Words Containing Character (0) | 2024.06.16 |
99클럽 코테 스터디 17일차 1512. Number of Good Pairs (0) | 2024.06.16 |