Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1.12 KB

풀이_LC1528.md

File metadata and controls

41 lines (28 loc) · 1.12 KB

🥴 LeetCode 1528. Shuffle String

  • Date : 2021.07.11(일)
  • Time : 15분

Problem

  • 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.

Constraints

  • 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).

Example

  • 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를 기준으로 하나씩 빼면서 원래의 문자열에 있던 문자열을 가져와준다.